This commit is contained in:
2023-12-01 20:47:42 +02:00
parent a09fc7ece3
commit 045f60e373
39 changed files with 1252 additions and 945 deletions
@@ -30,29 +30,8 @@ public class AccountServiceProfile : Profile
private void MapAccount()
{
CreateMap<Account, AccountDto>()
.ForMember(x => x.HasMotions, o => o.MapFrom(x => x.Motions!.Any()))
.ForMember(x => x.CurrentUserId, o => o.MapFrom<UserIdResolver>())
.ForMember(x => x.AccountAccess, o =>
{
o.MapFrom((src, dst) => src.AccessRights!.FirstOrDefault(x => x.UserId == dst.CurrentUserId));
})
.ForMember(x => x.Type, o =>
{
o.SetMappingOrder(1);
o.MapFrom((src, dst) => dst.AccountAccess?.Type.ToString());
})
.ForMember(x => x.Name, o =>
{
o.SetMappingOrder(1);
o.MapFrom((src, dst) => dst.AccountAccess?.Name ?? src.Name);
})
;
CreateMap<AccountDetailed, AccountDetailedDto>();
CreateMap<AccountAccess, AccountAccessDto>();
CreateMap<AccountAccountCategory, AccountAccountCategoryDto>();
CreateMap<AccountCategory, AccountCategoryDto>()
@@ -0,0 +1,17 @@
using AutoMapper;
using MyOffice.Core;
namespace MyOffice.Services;
public static class AutomapperExtensions
{
public static List<TTo> ToDto<TTo>(this IEnumerable<IDataModel> list, IMapper mapper)
{
return mapper.Map<List<TTo>>(list);
}
public static TTo ToDto<TTo>(this IDataModel item, IMapper mapper)
{
return mapper.Map<TTo>(item);
}
}
@@ -0,0 +1,12 @@
using MyOffice.Services.Identity;
namespace MyOffice.Services.Mapper;
public class BaseMappingAction
{
protected readonly IContextProvider ContextProvider;
public BaseMappingAction(IContextProvider contextProvider)
{
ContextProvider = contextProvider;
}
}
+13
View File
@@ -0,0 +1,13 @@
using AutoMapper;
namespace MyOffice.Services.Mapper;
public class BaseProfile<TSource, TDestination> : Profile
{
protected IMappingExpression<TSource, TDestination> Mapping;
public BaseProfile()
{
Mapping = CreateMap<TSource, TDestination>();
}
}