Browse Source

Implement object extensions for the identity module.

pull/3401/head
Halil İbrahim Kalkan 7 years ago
parent
commit
4cab2214f5
  1. 3
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateDtoBase.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs
  3. 6
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs
  4. 3
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/UpdateProfileDto.cs
  5. 8
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpIdentityApplicationModuleAutoMapperProfile.cs
  6. 16
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  7. 3
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs

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

@ -1,9 +1,10 @@
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity
{
public abstract class IdentityUserCreateOrUpdateDtoBase
public abstract class IdentityUserCreateOrUpdateDtoBase : ExtensibleObject
{
[Required]
[StringLength(IdentityUserConsts.MaxUserNameLength)]

2
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserDto.cs

@ -5,7 +5,7 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Identity
{
public class IdentityUserDto : FullAuditedEntityDto<Guid>, IMultiTenant, IHasConcurrencyStamp
public class IdentityUserDto : ExtensibleFullAuditedEntityDto<Guid>, IMultiTenant, IHasConcurrencyStamp
{
public Guid? TenantId { get; set; }

6
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/ProfileDto.cs

@ -1,6 +1,8 @@
namespace Volo.Abp.Identity
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity
{
public class ProfileDto
public class ProfileDto : ExtensibleObject
{
public string UserName { get; set; }

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

@ -1,8 +1,9 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity
{
public class UpdateProfileDto
public class UpdateProfileDto : ExtensibleObject
{
[StringLength(IdentityUserConsts.MaxUserNameLength)]
public string UserName { get; set; }

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

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

16
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Volo.Abp.Application.Dtos;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity
{
@ -45,6 +46,7 @@ namespace Volo.Abp.Identity
public virtual async Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)
{
var roles = await UserRepository.GetRolesAsync(id);
return new ListResultDto<IdentityRoleDto>(
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(roles)
);
@ -53,7 +55,14 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Users.Create)]
public virtual async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
{
var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id);
var user = new IdentityUser(
GuidGenerator.Create(),
input.UserName,
input.Email,
CurrentTenant.Id
);
input.MapExtraPropertiesTo(user);
(await UserManager.CreateAsync(user, input.Password)).CheckErrors();
await UpdateUserByInput(user, input);
@ -70,7 +79,10 @@ namespace Volo.Abp.Identity
user.ConcurrencyStamp = input.ConcurrencyStamp;
(await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
await UpdateUserByInput(user, input);
input.MapExtraPropertiesTo(user);
(await UserManager.UpdateAsync(user)).CheckErrors();
if (!input.Password.IsNullOrEmpty())
@ -78,7 +90,7 @@ namespace Volo.Abp.Identity
(await UserManager.RemovePasswordAsync(user)).CheckErrors();
(await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors();
}
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);

3
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Volo.Abp.Identity.Settings;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Settings;
using Volo.Abp.Users;
@ -43,6 +44,8 @@ namespace Volo.Abp.Identity
user.Name = input.Name;
user.Surname = input.Surname;
input.MapExtraPropertiesTo(user);
(await UserManager.UpdateAsync(user)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();

Loading…
Cancel
Save