Browse Source

Use automapper to map IdentityUser to UserEto

pull/3210/head
Halil İbrahim Kalkan 6 years ago
parent
commit
0200e5e340
  1. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDomainMappingProfile.cs
  3. 34
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs

2
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs

@ -29,7 +29,7 @@ namespace Volo.Abp.Identity
Configure<AbpDistributedEventBusOptions>(options =>
{
options.EtoMappings.Add<IdentityUser, UserEto>();
options.EtoMappings.Add<IdentityUser, UserEto>(typeof(AbpIdentityDomainModule));
options.EtoMappings.Add<IdentityClaimType, IdentityClaimTypeEto>(typeof(AbpIdentityDomainModule));
options.EtoMappings.Add<IdentityRole, IdentityRoleEto>(typeof(AbpIdentityDomainModule));
});

2
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDomainMappingProfile.cs

@ -1,4 +1,5 @@
using AutoMapper;
using Volo.Abp.Users;
namespace Volo.Abp.Identity
{
@ -6,6 +7,7 @@ namespace Volo.Abp.Identity
{
public IdentityDomainMappingProfile()
{
CreateMap<IdentityUser, UserEto>();
CreateMap<IdentityClaimType, IdentityClaimTypeEto>();
CreateMap<IdentityRole, IdentityRoleEto>();
}

34
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs

@ -8,12 +8,11 @@ using Microsoft.AspNetCore.Identity;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Guids;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Users;
namespace Volo.Abp.Identity
{
public class IdentityUser : FullAuditedAggregateRoot<Guid>, IUser, IMapTo<UserEto>
public class IdentityUser : FullAuditedAggregateRoot<Guid>, IUser
{
public virtual Guid? TenantId { get; protected set; }
@ -281,36 +280,5 @@ namespace Volo.Abp.Identity
{
return $"{base.ToString()}, UserName = {UserName}";
}
UserEto IMapTo<UserEto>.MapTo()
{
//TODO: Instead, consider to use automapper (but it makes dependency just for a small code part)??
return new UserEto
{
Name = Name,
Email = Email,
EmailConfirmed = EmailConfirmed,
Id = Id,
PhoneNumber = PhoneNumber,
PhoneNumberConfirmed = PhoneNumberConfirmed,
Surname = Surname,
TenantId = TenantId,
UserName = UserName
};
}
void IMapTo<UserEto>.MapTo(UserEto destination)
{
destination.Name = Name;
destination.Email = Email;
destination.EmailConfirmed = EmailConfirmed;
destination.Id = Id;
destination.PhoneNumber = PhoneNumber;
destination.PhoneNumberConfirmed = PhoneNumberConfirmed;
destination.Surname = Surname;
destination.TenantId = TenantId;
destination.UserName = UserName;
}
}
}

Loading…
Cancel
Save