This commit is contained in:
2023-07-28 21:18:18 +03:00
parent 5ecefe5756
commit 90f0386bfe
53 changed files with 3067 additions and 267 deletions
+12 -60
View File
@@ -1,12 +1,7 @@
namespace MyOffice.Web.Models.Account
{
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Core.Extensions;
using Data.Models.Accounts;
using Services.Account.Domain;
using Services.Identity;
using User;
public class AccountViewModel
{
@@ -20,71 +15,28 @@
public string CurrencyId { get; set; } = null!;
public string? CurrencyName { get; set; }
public bool AllowDelete { get; set; }
public bool AllowManage { get; set; }
public List<AccountCategoryViewModel>? Categories { get; set; }
[Required]
public string CategoryId { get; set; } = null!;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<AccessRightsViewModel>? AccessRights { get; set; }
}
public class ViewModelProfile : Profile
public class AccountAccessViewModel
{
public ViewModelProfile()
public class AccountAccessItemViewModel
{
CreateMap<Guid, string>().ConvertUsing(x => x.ToShort());
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(
IContextProvider contextProvider
)
{
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.Type, o => o.MapFrom(x => x.AccessRights!.FirstOrDefault(a => a.UserId == contextProvider.UserId)!.Type.ToString()))
.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))
;
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>();
}
}
/*public static class AccountViewModelExtensions
{
public static AccountViewModel ToModel(this AccountDto input)
{
return new AccountViewModel
{
Id = input.Id.ToShort(),
Name = input.Name,
CurrencyId = input.CurrencyGlobalId,
CurrencyName = input.CurrencyGlobal!.Name,
Categories = input.Categories!
.Select(x => x.Category!.ToModel())
.ToList(),
AccessRights = input.AccessRights!
.Select(x => x.ToModel())
.ToList(),
};
}
}*/
}