fix
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
namespace MyOffice.Web.Models.Account
|
||||
{
|
||||
using Data.Models.Accounts;
|
||||
using Services.Account.Domain;
|
||||
using Newtonsoft.Json;
|
||||
using User;
|
||||
|
||||
public class AccessRightsViewModel
|
||||
@@ -10,19 +9,16 @@
|
||||
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; }
|
||||
|
||||
public static class AccessRightsViewModelExtensions
|
||||
{
|
||||
public static AccessRightsViewModel ToModel(this AccountAccessDto accountAccess)
|
||||
{
|
||||
return new AccessRightsViewModel
|
||||
{
|
||||
User = accountAccess.User!.ToModel(),
|
||||
IsAllowManage = accountAccess.IsAllowManage,
|
||||
IsAllowRead = accountAccess.IsAllowRead,
|
||||
IsAllowWrite = accountAccess.IsAllowWrite,
|
||||
};
|
||||
}
|
||||
#region DEBUG
|
||||
|
||||
[JsonIgnore]
|
||||
public Guid UserId { get; set; }
|
||||
[JsonIgnore]
|
||||
public Guid OwnerId { get; set; }
|
||||
|
||||
#endregion DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
};
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
namespace MyOffice.Web.Models.Account;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Services.Identity;
|
||||
using Services.Account.Domain;
|
||||
using Services.Mapper;
|
||||
using System.Security.Cryptography;
|
||||
using Core.Extensions;
|
||||
using User;
|
||||
using static MyOffice.Web.Models.Account.AccountAccessViewModel;
|
||||
|
||||
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<AccountAccessItemViewModel, AccountAccessDto>()
|
||||
.ForMember(x => x.IsAllowWrite, o => o.MapFrom(x => x.AllowWrite))
|
||||
;
|
||||
|
||||
CreateMap<AccountCategoryDto, AccountCategoryViewModel>()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace MyOffice.Web.Models.Account;
|
||||
|
||||
using AutoMapper;
|
||||
using Core.Extensions;
|
||||
|
||||
public class ViewModelProfile : Profile
|
||||
{
|
||||
public ViewModelProfile()
|
||||
{
|
||||
CreateMap<Guid, string>().ConvertUsing(x => x.ToShort());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user