namespace MyOffice.Services.Account.Domain;
using AutoMapper;
using Core.Attributes;
using Data.Models.Accounts;
using Data.Models.Users;
using Mapper;
using MyOffice.Services.Identity;
[Link(typeof(AccountAccess))]
[Link(typeof(AccountServiceProfile))]
public class AccountAccessDto
{
public Guid AccountId { get; set; }
public AccountDto? Account { get; set; }
///
/// User can access to account
///
public Guid UserId { get; set; }
public UserDto? User { get; set; }
public bool IsAllowRead { get; set; }
public bool IsAllowWrite { get; set; }
public bool IsAllowManage { get; set; }
public bool IsOwner { get; set; }
public AccountAccessTypeEnum Type { get; set; }
///
/// Who add access
///
public Guid OwnerId { get; set; }
public UserDto? Owner { get; set; }
public string? Name { get; set; }
}
public class AccountAccessDtoProfile: Profile
{
public AccountAccessDtoProfile()
{
CreateMap()
.AfterMap()
;
}
}
public class AccountAccessDtoMappingAction: IMappingAction
{
private readonly IContextProvider _contextProvider;
public AccountAccessDtoMappingAction(IContextProvider contextProvider)
{
_contextProvider = contextProvider;
}
public void Process(AccountAccess source, AccountAccessDto destination, ResolutionContext context)
{
destination.IsOwner = destination.OwnerId == _contextProvider.UserId;
}
}