From 4c6cee1f36bf09be26c971c410b7c374f67aa9f0 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 29 Jun 2021 18:43:50 +0800 Subject: [PATCH 1/2] Convert property to enum if necessary. --- .../Data/ExtraPropertyDictionaryExtensions.cs | 30 +++++++++++++++++++ .../Pages/Identity/Roles/CreateModal.cshtml | 4 +++ .../Pages/Identity/Roles/EditModal.cshtml | 4 +++ .../Pages/Identity/Users/CreateModal.cshtml | 4 +++ .../Pages/Identity/Users/EditModal.cshtml | 4 +++ .../Tenants/CreateModal.cshtml | 4 +++ .../TenantManagement/Tenants/EditModal.cshtml | 4 +++ 7 files changed, 54 insertions(+) create mode 100644 framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/ExtraPropertyDictionaryExtensions.cs diff --git a/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/ExtraPropertyDictionaryExtensions.cs b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/ExtraPropertyDictionaryExtensions.cs new file mode 100644 index 0000000000..0c6b9dff67 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/ExtraPropertyDictionaryExtensions.cs @@ -0,0 +1,30 @@ +using System; + +namespace Volo.Abp.Data +{ + public static class ExtraPropertyDictionaryExtensions + { + public static T ToEnum(this ExtraPropertyDictionary extraPropertyDictionary, string key) + where T : Enum + { + if (extraPropertyDictionary[key].GetType() == typeof(T)) + { + return (T)extraPropertyDictionary[key]; + } + + extraPropertyDictionary[key] = Enum.Parse(typeof(T), extraPropertyDictionary[key].ToString(), ignoreCase: true); + return (T)extraPropertyDictionary[key]; + } + + public static object ToEnum(this ExtraPropertyDictionary extraPropertyDictionary, string key, Type enumType) + { + if (!enumType.IsEnum || extraPropertyDictionary[key].GetType() == enumType) + { + return extraPropertyDictionary[key]; + } + + extraPropertyDictionary[key] = Enum.Parse(enumType, extraPropertyDictionary[key].ToString(), ignoreCase: true); + return extraPropertyDictionary[key]; + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml index 02a24b4084..4ebac325fb 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml @@ -30,6 +30,10 @@ { if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) { + if (propertyInfo.Type.IsEnum) + { + Model.Role.ExtraProperties.ToEnum(propertyInfo.Name, propertyInfo.Type); + } Date: Tue, 29 Jun 2021 19:47:37 +0800 Subject: [PATCH 2/2] Fix convert issue in AbpCrudPageBase. --- framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 19ace62aca..ea7e2236ef 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -494,17 +494,17 @@ namespace Volo.Abp.BlazoriseUI await HandleErrorAsync(ex); } } - + protected virtual Task OnDeletingEntityAsync() { return Task.CompletedTask; } - + protected virtual async Task OnDeletedEntityAsync() { await GetEntitiesAsync(); await InvokeAsync(StateHasChanged); - } + } protected virtual string GetDeleteConfirmationMessage(TListViewModel entity) { @@ -596,7 +596,7 @@ namespace Volo.Abp.BlazoriseUI if (propertyInfo.Type.IsEnum) { column.ValueConverter = (val) => - EnumHelper.GetLocalizedMemberName(propertyInfo.Type, val, StringLocalizerFactory); + EnumHelper.GetLocalizedMemberName(propertyInfo.Type, val.As().ExtraProperties[propertyInfo.Name], StringLocalizerFactory); } yield return column;