Files
myoffice/MyOffice.Web/Models/Account/AccountViewModel.cs
T
2023-12-01 20:47:42 +02:00

94 lines
2.4 KiB
C#

namespace MyOffice.Web.Models.Account;
using AutoMapper;
using MyOffice.Services.Account.Domain;
using MyOffice.Services.Identity;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
public class AccountViewModel: IResponseModel
{
public string? Id { get; set; }
[Required]
public string Name { get; set; } = null!;
public string Type { get; set; } = null!;
[Required]
public string CurrencyId { get; set; } = null!;
public string? CurrencyName { get; set; }
public List<AccountCategoryViewModel>? Categories { get; set; }
[Required]
public string CategoryId { get; set; } = null!;
#region Permissions
public List<AccessRightsViewModel>? AccessRights { get; set; }
public bool AllowRead { get; set; }
public bool AllowWrite { get; set; }
public bool AllowDelete { get; set; }
public bool AllowManage { get; set; }
#endregion Permissions
}
public static class AccountViewModelExtensions
{
public static List<AccountViewModel> ToViewModel(this List<AccountDto> accounts, IMapper mapper)
{
return mapper.Map<List<AccountViewModel>>(accounts.OrderBy(x => x.Name));
}
}
public class AccountAccessViewModel
{
public class AccountAccessItemViewModel
{
public string UserId { get; set; } = null!;
public bool AllowWrite { get; set; }
}
public string? Email { get; set; }
public bool AllowWrite { get; set; }
public List<AccountAccessItemViewModel> Accesses { get; set; } = null!;
}
public class AccountViewModelProfile : Profile
{
public AccountViewModelProfile()
{
CreateMap<AccountDto, AccountViewModel>()
.ForMember(x => x.CurrencyId, o => o.MapFrom(x => x.CurrencyGlobalId))
.ForMember(x => x.CurrencyName, o => o.MapFrom(x => x.Currency!.Name))
.AfterMap<AccountViewModelMappingAction>()
;
CreateMap<AccountAccessDto, AccessRightsViewModel>()
.AfterMap<AccessRightsViewModelMappingAction>()
;
}
}
public class AccountViewModelMappingAction : IMappingAction<AccountDto, AccountViewModel>
{
public void Process(AccountDto source, AccountViewModel destination, ResolutionContext context)
{
}
}
public class AccessRightsViewModelMappingAction : IMappingAction<AccountAccessDto, AccessRightsViewModel>
{
private readonly IContextProvider _contextProvider;
public AccessRightsViewModelMappingAction(IContextProvider contextProvider)
{
_contextProvider = contextProvider;
}
public void Process(AccountAccessDto source, AccessRightsViewModel destination, ResolutionContext context)
{
}
}