Browse Source

Use AutoMapper on the Identity Blazor UI

pull/5399/head
Halil İbrahim Kalkan 6 years ago
parent
commit
786d538da5
  1. 13
      modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorAutoMapperProfile.cs
  2. 16
      modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs
  3. 28
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs
  4. 6
      modules/identity/src/Volo.Abp.Identity.Blazor/Volo.Abp.Identity.Blazor.csproj
  5. 3
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Shared/LoginDisplay.razor

13
modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorAutoMapperProfile.cs

@ -0,0 +1,13 @@
using AutoMapper;
namespace Volo.Abp.Identity.Blazor
{
public class AbpIdentityBlazorAutoMapperProfile : Profile
{
public AbpIdentityBlazorAutoMapperProfile()
{
CreateMap<IdentityRoleDto, IdentityRoleUpdateDto>()
.MapExtraProperties();
}
}
}

16
modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs

@ -1,13 +1,25 @@
using Volo.Abp.Modularity; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
using Volo.Abp.BlazoriseUI; using Volo.Abp.BlazoriseUI;
namespace Volo.Abp.Identity.Blazor namespace Volo.Abp.Identity.Blazor
{ {
[DependsOn( [DependsOn(
typeof(AbpIdentityHttpApiClientModule), typeof(AbpIdentityHttpApiClientModule),
typeof(AbpBlazoriseUIModule) typeof(AbpBlazoriseUIModule),
typeof(AbpAutoMapperModule)
)] )]
public class AbpIdentityBlazorModule : AbpModule public class AbpIdentityBlazorModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAutoMapperObjectMapper<AbpIdentityBlazorModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<AbpIdentityBlazorAutoMapperProfile>(validate: true);
});
}
} }
} }

28
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Components;
using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Components.WebAssembly; using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.Identity.Blazor.Pages.Identity namespace Volo.Abp.Identity.Blazor.Pages.Identity
{ {
@ -15,6 +16,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
{ {
[Inject] private IIdentityRoleAppService RoleAppService { get; set; } [Inject] private IIdentityRoleAppService RoleAppService { get; set; }
[Inject] private IUiMessageService UiMessageService { get; set; } [Inject] private IUiMessageService UiMessageService { get; set; }
[Inject] private IObjectMapper<AbpIdentityBlazorModule> ObjectMapper { get; set; }
private int _currentPage; private int _currentPage;
private string _currentSorting; private string _currentSorting;
@ -22,17 +24,17 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
private IReadOnlyList<IdentityRoleDto> _roles; private IReadOnlyList<IdentityRoleDto> _roles;
private IdentityRoleCreateDto _newRole; private IdentityRoleCreateDto _newRole; //TODO: Would be better to create a UI model class
private Guid _editingRoleId; private Guid _editingRoleId;
private IdentityRoleUpdateDto _editingRole; private IdentityRoleUpdateDto _editingRole; //TODO: Would be better to create a UI model class
private Modal _createModal; private Modal _createModal;
private Modal _editModal; private Modal _editModal;
public RoleManagement() public RoleManagement()
{ {
_newRole = new IdentityRoleCreateDto(); _newRole = new IdentityRoleCreateDto(); //TODO: Can we discard this (create on modal opening)?
_editingRole = new IdentityRoleUpdateDto(); _editingRole = new IdentityRoleUpdateDto(); //TODO: Can we discard this (create on modal opening)?
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -62,6 +64,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
.JoinAsString(","); .JoinAsString(",");
_currentPage = e.Page - 1; _currentPage = e.Page - 1;
await GetRolesAsync(); await GetRolesAsync();
StateHasChanged(); StateHasChanged();
} }
@ -69,6 +72,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
private void OpenCreateModal() private void OpenCreateModal()
{ {
_newRole = new IdentityRoleCreateDto(); _newRole = new IdentityRoleCreateDto();
_createModal.Show(); _createModal.Show();
} }
@ -82,18 +86,8 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
var role = await RoleAppService.GetAsync(id); var role = await RoleAppService.GetAsync(id);
_editingRoleId = id; _editingRoleId = id;
_editingRole = ObjectMapper.Map<IdentityRoleDto, IdentityRoleUpdateDto>(role);
//TODO: User AutoMapper!
_editingRole = new IdentityRoleUpdateDto
{
Name = role.Name,
ConcurrencyStamp = role.ConcurrencyStamp,
IsDefault = role.IsDefault,
IsPublic = role.IsPublic
};
role.MapExtraPropertiesTo(_editingRole);
_editModal.Show(); _editModal.Show();
} }
@ -106,6 +100,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
{ {
await RoleAppService.CreateAsync(_newRole); await RoleAppService.CreateAsync(_newRole);
await GetRolesAsync(); await GetRolesAsync();
_createModal.Hide(); _createModal.Hide();
} }
@ -113,6 +108,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
{ {
await RoleAppService.UpdateAsync(_editingRoleId, _editingRole); await RoleAppService.UpdateAsync(_editingRoleId, _editingRole);
await GetRolesAsync(); await GetRolesAsync();
_editModal.Hide(); _editModal.Hide();
} }

6
modules/identity/src/Volo.Abp.Identity.Blazor/Volo.Abp.Identity.Blazor.csproj

@ -9,8 +9,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BlazoriseUI\Volo.Abp.BlazoriseUI.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BlazoriseUI\Volo.Abp.BlazoriseUI.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

3
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Shared/LoginDisplay.razor

@ -1,5 +1,4 @@
@using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager @inject SignOutSessionStateManager SignOutManager

Loading…
Cancel
Save