Files
mixtape/zero.Web/Mapper/UserMapperConfig.cs
T

81 lines
2.6 KiB
C#
Raw Normal View History

2020-04-24 12:46:25 +02:00
using System;
using zero.Core.Entities;
2020-04-17 15:32:33 +02:00
using zero.Web.Models;
namespace zero.Web.Mapper
{
2020-04-17 15:51:11 +02:00
public class UserMapperConfig : IMapperConfig
2020-04-17 15:32:33 +02:00
{
/// <inheritdoc />
public void Configure(IMapper config)
{
config.CreateMap<User, UserEditModel>((source, target) =>
{
target.Id = source.Id;
target.Name = source.Name;
target.IsActive = source.IsActive;
target.CreatedDate = source.CreatedDate;
target.IsSuper = source.IsSuper;
target.Email = source.Email;
target.IsEmailConfirmed = source.IsEmailConfirmed;
target.Avatar = source.Avatar;
target.LanguageId = source.LanguageId;
target.Roles = source.Roles;
target.Claims = source.Claims;
target.LockoutEnd = source.LockoutEnd;
});
config.CreateMap<UserEditModel, User>((source, target) =>
{
target.Name = source.Name;
target.IsActive = source.IsActive;
target.IsSuper = source.IsSuper;
target.Email = source.Email;
target.Avatar = source.Avatar;
target.LanguageId = source.LanguageId;
target.Roles = source.Roles;
target.Claims = source.Claims;
target.LockoutEnd = source.LockoutEnd;
});
2020-04-24 12:46:25 +02:00
config.CreateMap<User, UserListModel>((source, target) =>
{
target.Id = source.Id;
target.Name = source.Name;
target.IsActive = source.IsActive && (!source.LockoutEnabled || !source.LockoutEnd.HasValue);
target.Email = source.Email;
2020-04-24 18:32:54 +02:00
target.Avatar = "https://fifty.brothers.studio/Media/Avatars/tobi.jpg"; // TODO //source.Avatar?.Source;
2020-04-24 12:46:25 +02:00
target.Roles = String.Join(", ", source.Roles); // TODO get name from alias
});
config.CreateMap<UserRole, UserRoleEditModel>((source, target) =>
{
target.Id = source.Id;
target.Name = source.Name;
target.IsActive = source.IsActive;
target.CreatedDate = source.CreatedDate;
target.Description = source.Description;
target.Icon = source.Icon;
target.Claims = source.Claims;
});
config.CreateMap<UserRoleEditModel, UserRole>((source, target) =>
{
target.Name = source.Name;
target.IsActive = source.IsActive;
target.Description = source.Description;
target.Icon = source.Icon;
target.Claims = source.Claims;
});
config.CreateMap<UserRole, UserRoleListModel>((source, target) =>
{
target.Id = source.Id;
target.Name = source.Name;
target.CountClaims = source.Claims.Count;
target.Icon = source.Icon;
});
2020-04-17 15:32:33 +02:00
}
}
}