Browse Source

Apply object extensions for identity role app service.

pull/3401/head
Halil İbrahim Kalkan 7 years ago
parent
commit
b6a92c0e00
  1. 1
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs
  2. 3
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleCreateOrUpdateDtoBase.cs
  3. 4
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs
  4. 5
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs
  5. 22
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

1
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;

3
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleCreateOrUpdateDtoBase.cs

@ -1,8 +1,9 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
public class IdentityRoleCreateOrUpdateDtoBase public class IdentityRoleCreateOrUpdateDtoBase : ExtensibleObject
{ {
[Required] [Required]
[StringLength(IdentityRoleConsts.MaxNameLength)] [StringLength(IdentityRoleConsts.MaxNameLength)]

4
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs

@ -4,12 +4,12 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
public class IdentityRoleDto : EntityDto<Guid>, IHasConcurrencyStamp public class IdentityRoleDto : ExtensibleEntityDto<Guid>, IHasConcurrencyStamp
{ {
public string Name { get; set; } public string Name { get; set; }
public bool IsDefault { get; set; } public bool IsDefault { get; set; }
public bool IsStatic { get; set; } public bool IsStatic { get; set; }
public bool IsPublic { get; set; } public bool IsPublic { get; set; }

5
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs

@ -7,7 +7,10 @@ namespace Volo.Abp.Identity
public AbpIdentityApplicationModuleAutoMapperProfile() public AbpIdentityApplicationModuleAutoMapperProfile()
{ {
CreateMap<IdentityUser, IdentityUserDto>(); CreateMap<IdentityUser, IdentityUserDto>();
CreateMap<IdentityRole, IdentityRoleDto>();
CreateMap<IdentityRole, IdentityRoleDto>()
.MapExtraProperties();
CreateMap<IdentityUser, ProfileDto>(); CreateMap<IdentityUser, ProfileDto>();
} }
} }

22
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
@ -24,14 +25,16 @@ namespace Volo.Abp.Identity
public virtual async Task<IdentityRoleDto> GetAsync(Guid id) public virtual async Task<IdentityRoleDto> GetAsync(Guid id)
{ {
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>( return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(
await RoleManager.GetByIdAsync(id)); await RoleManager.GetByIdAsync(id)
);
} }
public virtual async Task<ListResultDto<IdentityRoleDto>> GetAllListAsync() public virtual async Task<ListResultDto<IdentityRoleDto>> GetAllListAsync()
{ {
var list = await RoleRepository.GetListAsync(); var list = await RoleRepository.GetListAsync();
return new ListResultDto<IdentityRoleDto>( return new ListResultDto<IdentityRoleDto>(
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list)); ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list)
);
} }
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input) public virtual async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
@ -48,10 +51,17 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Roles.Create)] [Authorize(IdentityPermissions.Roles.Create)]
public virtual async Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input) public virtual async Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input)
{ {
var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); var role = new IdentityRole(
GuidGenerator.Create(),
input.Name,
CurrentTenant.Id
)
{
IsDefault = input.IsDefault,
IsPublic = input.IsPublic
};
role.IsDefault = input.IsDefault; input.MapExtraPropertiesTo(role);
role.IsPublic = input.IsPublic;
(await RoleManager.CreateAsync(role)).CheckErrors(); (await RoleManager.CreateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
@ -70,6 +80,8 @@ namespace Volo.Abp.Identity
role.IsDefault = input.IsDefault; role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic; role.IsPublic = input.IsPublic;
input.MapExtraPropertiesTo(role);
(await RoleManager.UpdateAsync(role)).CheckErrors(); (await RoleManager.UpdateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();

Loading…
Cancel
Save