From a62fb7be317213ce8d62686bdf12ea48ce8695e0 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 3 Nov 2020 12:21:30 +0100 Subject: [PATCH] Validation for Tenant create and edit modals --- .../TenantCreateOrUpdateDtoBase.cs | 3 +- .../TenantManagement/TenantManagement.razor | 175 +++++++++++------- .../TenantManagement.razor.cs | 32 ++-- 3 files changed, 127 insertions(+), 83 deletions(-) diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/TenantCreateOrUpdateDtoBase.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/TenantCreateOrUpdateDtoBase.cs index 9f047af2fd..eb5b71ba05 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/TenantCreateOrUpdateDtoBase.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/TenantCreateOrUpdateDtoBase.cs @@ -8,11 +8,12 @@ namespace Volo.Abp.TenantManagement { [Required] [DynamicStringLength(typeof(TenantConsts), nameof(TenantConsts.MaxNameLength))] + [Display(Name = "TenantName")] public string Name { get; set; } public TenantCreateOrUpdateDtoBase() : base(false) { - + } } } \ No newline at end of file diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor index 81c61ae9fa..1d62dc6be0 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor @@ -1,15 +1,15 @@ @page "/tenant-management/tenants" -@attribute [Authorize(TenantManagementPermissions.Tenants.Default)] +@attribute [Authorize( TenantManagementPermissions.Tenants.Default )] @using Microsoft.AspNetCore.Authorization @using Volo.Abp.FeatureManagement.Blazor.Components @using Microsoft.AspNetCore.Components.Forms - +@using Volo.Abp.TenantManagement.Localization +@inject AbpBlazorMessageLocalizerHelper LH @inherits AbpCrudPageBase - @* ************************* PAGE HEADER ************************* *@ -

@L["Tenants"]

+ @L["Tenants"]
@if (HasCreatePermission) @@ -65,31 +65,52 @@ { - - - @L["NewTenant"] - - - - - - @L["TenantName"] - - - - @L["DisplayName:AdminEmailAddress"] - - - - @L["DisplayName:AdminPassword"] - - - - - - - - + +
+ + @L["NewTenant"] + + + + + + + + @L["TenantName"] + + + + + + + + + + @L["DisplayName:AdminEmailAddress"] + + + + + + + + + + @L["DisplayName:AdminPassword"] + + + + + + + + + + + + + +
} @@ -99,23 +120,31 @@ { - - - @L["Edit"] - - - - - - @L["TenantName"] - - - - - - - - + +
+ + @L["Edit"] + + + + + + + @L["TenantName"] + + + + + + + + + + + + + +
} @@ -125,30 +154,36 @@ { - - - @L["ConnectionStrings"] - - - - - - @L["DisplayName:DefaultConnectionString"] - - - @if (!TenantInfo.UseSharedDatabase) - { - - @L["DisplayName:DefaultConnectionString"] - - - } - - - - - - + +
+ + @L["ConnectionStrings"] + + + + + + + @L["DisplayName:DefaultConnectionString"] + + + + @if (!TenantInfo.UseSharedDatabase) + { + + + @L["DisplayName:DefaultConnectionString"] + + + + } + + + + + + +
} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs index e5fcc9c4a3..ad33b68e5c 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Blazorise; using Microsoft.AspNetCore.Authorization; @@ -20,9 +21,10 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement protected FeatureManagementModal FeatureManagementModal; protected Modal ManageConnectionStringModal; + protected Validations ManageConnectionStringValidations; protected TenantInfoModel TenantInfo; - + public TenantManagement() { LocalizationResource = typeof(AbpTenantManagementResource); @@ -36,7 +38,7 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement TenantInfo = new TenantInfoModel(); } - + protected async override Task SetPermissionsAsync() { await base.SetPermissionsAsync(); @@ -47,6 +49,8 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement protected virtual async Task OpenEditConnectionStringModalAsync(Guid id) { + ManageConnectionStringValidations.ClearAll(); + var tenantConnectionString = await AppService.GetDefaultConnectionStringAsync(id); TenantInfo = new TenantInfoModel @@ -67,18 +71,21 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement protected virtual async Task UpdateConnectionStringAsync() { - await CheckPolicyAsync(ManageConnectionStringsPolicyName); - - if (TenantInfo.UseSharedDatabase || TenantInfo.DefaultConnectionString.IsNullOrWhiteSpace()) + if (ManageConnectionStringValidations.ValidateAll()) { - await AppService.DeleteDefaultConnectionStringAsync(TenantInfo.Id); + await CheckPolicyAsync(ManageConnectionStringsPolicyName); + + if (TenantInfo.UseSharedDatabase || TenantInfo.DefaultConnectionString.IsNullOrWhiteSpace()) + { + await AppService.DeleteDefaultConnectionStringAsync(TenantInfo.Id); + } + else + { + await AppService.UpdateDefaultConnectionStringAsync(TenantInfo.Id, TenantInfo.DefaultConnectionString); + } + + ManageConnectionStringModal.Hide(); } - else - { - await AppService.UpdateDefaultConnectionStringAsync(TenantInfo.Id, TenantInfo.DefaultConnectionString); - } - - ManageConnectionStringModal.Hide(); } protected override string GetDeleteConfirmationMessage(TenantDto entity) @@ -93,6 +100,7 @@ namespace Volo.Abp.TenantManagement.Blazor.Pages.TenantManagement public bool UseSharedDatabase { get; set; } + [Required] public string DefaultConnectionString { get; set; } } } \ No newline at end of file