108 lines
3.4 KiB
C#
108 lines
3.4 KiB
C#
namespace MyOffice.Web.Models.Account;
|
|
|
|
using AutoMapper;
|
|
|
|
using MyOffice.Services.Currency.Domain;
|
|
using Currency;
|
|
using Item;
|
|
using Motion;
|
|
using Services.Account.Domain;
|
|
using User;
|
|
using MyOffice.Services.Identity;
|
|
|
|
/*public class CustomResolver : IValueResolver<AccountAccessDto, AccessRightsViewModel, bool>
|
|
{
|
|
private readonly ILogger<CustomResolver> _logger;
|
|
private readonly IContextProvider _contextProvider;
|
|
|
|
public CustomResolver(
|
|
ILogger<CustomResolver> logger,
|
|
IContextProvider contextProvider
|
|
)
|
|
{
|
|
_logger = logger;
|
|
_contextProvider = contextProvider;
|
|
}
|
|
|
|
public bool Resolve(AccountAccessDto source, AccessRightsViewModel destination, bool member, ResolutionContext context)
|
|
{
|
|
return source.OwnerId == _contextProvider.UserId;
|
|
}
|
|
}*/
|
|
|
|
public class PublicationSystemResolver : IMemberValueResolver<object, object, string, bool>
|
|
{
|
|
private readonly IContextProvider _contextProvider;
|
|
|
|
public PublicationSystemResolver(
|
|
IContextProvider contextProvider
|
|
)
|
|
{
|
|
this._contextProvider = contextProvider;
|
|
}
|
|
|
|
public bool Resolve(object source, object destination, string sourceMember, bool destMember, ResolutionContext context)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public class AccountViewModelGeneralProfile : Profile
|
|
{
|
|
public AccountViewModelGeneralProfile()
|
|
{
|
|
CreateMap<AccountDetailedDto, AccountDetailedViewModel>()
|
|
.ForMember(x => x.Account, o => o.MapFrom(x => x.Account))
|
|
;
|
|
|
|
CreateMap<UserDto, UserViewModel>();
|
|
|
|
CreateMap<MyOffice.Data.Models.Users.User, UserViewModel>();
|
|
|
|
CreateMap<AccountAccountCategoryDto, AccountCategoryViewModel>()
|
|
.ForMember(x => x.Id, o => o.MapFrom(x => x.CategoryId))
|
|
.ForMember(x => x.Name, o => o.MapFrom(x => x.Category!.Name))
|
|
;
|
|
|
|
CreateMap<AccountAccessViewModel.AccountAccessItemViewModel, AccountAccessDto>()
|
|
.ForMember(x => x.IsAllowWrite, o => o.MapFrom(x => x.AllowWrite))
|
|
;
|
|
|
|
CreateMap<AccountCategoryDto, AccountCategoryViewModel>()
|
|
;
|
|
|
|
CreateMap<AccountAccessInviteDto, AccountAccessInviteViewModel>()
|
|
.ForMember(x => x.AllowWrite, o => o.MapFrom(x => x.IsAllowWrite))
|
|
;
|
|
|
|
CreateMap<MotionDto, MotionViewModel>()
|
|
;
|
|
|
|
CreateMap<ItemDto, ItemViewModel>()
|
|
.ForMember(x => x.Category, o => o.MapFrom(x => x.Category!.Name))
|
|
;
|
|
|
|
CreateMap<ItemCategoryDto, ItemCategoryViewModel>()
|
|
.ForMember(x => x.Internal, o => o.MapFrom(x => x.IsInternal))
|
|
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.Items.Any() && x.Id != x.UserId))
|
|
.ForMember(x => x.SortOrder, o => o.MapFrom(x => x.Id == x.UserId ? 1 : 0))
|
|
;
|
|
|
|
CreateMap<CurrencyGlobalDto, CurrencyGlobalViewModel>();
|
|
|
|
CreateMap<CurrencyDto, CurrencyViewModel>();
|
|
|
|
CreateMap<CurrencyRateDto, CurrencyRateViewModel>();
|
|
|
|
CreateMap<CurrencyWithRateDto, CurrencyViewModel>()
|
|
.ForMember(x => x.Id, o => o.MapFrom(x => x.Currency.Id))
|
|
.ForMember(x => x.Code, o => o.MapFrom(x => x.Currency.CurrencyGlobalId))
|
|
.ForMember(x => x.Name, o => o.MapFrom(x => x.Currency.Name))
|
|
.ForMember(x => x.ShortName, o => o.MapFrom(x => x.Currency.ShortName))
|
|
.ForMember(x => x.Rate, o => o.MapFrom(x => x.Rate == null ? (decimal?)null : x.Rate.Rate))
|
|
.ForMember(x => x.IsPrimary, o => o.MapFrom(x => x.Currency.IsPrimary))
|
|
.ForMember(x => x.Quantity, o => o.MapFrom(x => x.Rate == null ? (int?)null : x.Rate.Quantity))
|
|
.ForMember(x => x.RateDate, o => o.MapFrom(x => x.Rate == null ? (DateTime?)null : x.Rate.DateTime))
|
|
;
|
|
}
|
|
} |