106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
namespace MyOffice.Web.Models.Account;
|
|
|
|
using AutoMapper;
|
|
|
|
using MyOffice.Services.Currency.Domain;
|
|
using MyOffice.Services.Identity;
|
|
using Currency;
|
|
using Item;
|
|
using Motion;
|
|
using Services.Account.Domain;
|
|
using User;
|
|
|
|
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 AccountViewModelProfile : Profile
|
|
{
|
|
public AccountViewModelProfile()
|
|
{
|
|
CreateMap<AccountDetailedDto, AccountDetailedViewModel>()
|
|
.ForMember(x => x.Account, o => o.MapFrom(x => x.Account))
|
|
;
|
|
|
|
CreateMap<UserDto, UserViewModel>();
|
|
|
|
CreateMap<MyOffice.Data.Models.Users.User, UserViewModel>();
|
|
|
|
CreateMap<AccountDto, AccountViewModel>()
|
|
.ForMember(x => x.CurrencyId, o => o.MapFrom(x => x.CurrencyGlobalId))
|
|
.ForMember(x => x.CurrencyName, o => o.MapFrom(x => x.Currency!.Name))
|
|
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.HasMotions))
|
|
.ForMember(x => x.AllowManage, o => o.MapFrom(x => x.AccessRights!.Any(a => a.OwnerId == x.CurrentUserId)))
|
|
.ForMember(x => x.AccessRights, o => o.MapFrom((s, d) => s.OwnerId != s.CurrentUserId ? null : s.AccessRights))
|
|
;
|
|
|
|
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<AccountAccessDto, AccessRightsViewModel>()
|
|
.ForMember(x => x.IsAllowDelete, o => o.MapFrom(
|
|
(src, dst) => src.Account!.OwnerId == src.Account.CurrentUserId && src.UserId != src.Account.CurrentUserId))
|
|
.ForMember(x => x.IsOwner, o => o.MapFrom(
|
|
(src, dst) => src.OwnerId == src.UserId))
|
|
;
|
|
|
|
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))
|
|
;
|
|
}
|
|
} |