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
@@ -1,24 +1,13 @@
namespace MyOffice.Web.Models.Account
namespace MyOffice.Web.Models.Account;
using User;
public class AccessRightsViewModel
{
using Newtonsoft.Json;
using User;
public class AccessRightsViewModel
{
public UserViewModel User { get; set; } = null!;
public bool IsAllowRead { get; set; }
public bool IsAllowWrite { get; set; }
public bool IsAllowManage { get; set; }
public bool IsAllowDelete { get; set; }
public bool IsOwner { get; set; }
#region DEBUG
[JsonIgnore]
public Guid UserId { get; set; }
[JsonIgnore]
public Guid OwnerId { get; set; }
#endregion DEBUG
}
public UserViewModel? User { get; set; } = null!;
public bool AllowRead { get; set; }
public bool AllowWrite { get; set; }
public bool AllowManage { get; set; }
public bool AllowDelete { get; set; }
public bool IsOwner { get; set; }
}
@@ -5,7 +5,7 @@ using MyOffice.Services.Account.Domain;
using System.ComponentModel.DataAnnotations;
[Link(typeof(AccountCategoryDto))]
public class AccountCategoryViewModel
public class AccountCategoryViewModel: IResponseModel
{
public string? Id { get; set; }
+89 -37
View File
@@ -1,42 +1,94 @@
namespace MyOffice.Web.Models.Account
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
{
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
public string? Id { get; set; }
public class AccountViewModel
[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)
{
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 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 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!;
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)
{
}
}
@@ -3,14 +3,14 @@
using AutoMapper;
using MyOffice.Services.Currency.Domain;
using MyOffice.Services.Identity;
using Currency;
using Item;
using Motion;
using Services.Account.Domain;
using User;
using MyOffice.Services.Identity;
public class CustomResolver : IValueResolver<AccountAccessDto, AccessRightsViewModel, bool>
/*public class CustomResolver : IValueResolver<AccountAccessDto, AccessRightsViewModel, bool>
{
private readonly ILogger<CustomResolver> _logger;
private readonly IContextProvider _contextProvider;
@@ -28,11 +28,28 @@ public class CustomResolver : IValueResolver<AccountAccessDto, AccessRightsViewM
{
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 AccountViewModelProfile : Profile
public class AccountViewModelGeneralProfile : Profile
{
public AccountViewModelProfile()
public AccountViewModelGeneralProfile()
{
CreateMap<AccountDetailedDto, AccountDetailedViewModel>()
.ForMember(x => x.Account, o => o.MapFrom(x => x.Account))
@@ -42,26 +59,11 @@ public class AccountViewModelProfile : Profile
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))
;