sync full source from private myoffice
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public enum AccessInviteStatus
|
||||
{
|
||||
success,
|
||||
account_not_found,
|
||||
access_exists,
|
||||
invite_exists,
|
||||
forbidden,
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using Data.Models.Accounts;
|
||||
using MyOffice.Services.Identity;
|
||||
|
||||
public class AccountAccessDto
|
||||
{
|
||||
public Guid AccountId { get; set; }
|
||||
public AccountDto? Account { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User can access to account
|
||||
/// </summary>
|
||||
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; }
|
||||
/// <summary>
|
||||
/// Who add access
|
||||
/// </summary>
|
||||
public Guid OwnerId { get; set; }
|
||||
public UserDto? Owner { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class AccountAccessDtoProfile : Profile
|
||||
{
|
||||
public AccountAccessDtoProfile()
|
||||
{
|
||||
CreateMap<AccountAccess, AccountAccessDto>()
|
||||
.AfterMap<AccountAccessDtoMappingAction>()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public class AccountAccessDtoMappingAction : IMappingAction<AccountAccess, AccountAccessDto>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <see cref="MyOffice.Data.Models.Accounts.AccountAccessInvite"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using Data.Models.Accounts;
|
||||
|
||||
public class AccountAccessInviteDto
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public string Account { get; set; } = null!;
|
||||
public bool IsAllowWrite { get; set; }
|
||||
}
|
||||
|
||||
public class AccountAccessInviteDtoProfile: Profile
|
||||
{
|
||||
public AccountAccessInviteDtoProfile()
|
||||
{
|
||||
CreateMap<AccountAccessInvite, AccountAccessInviteDto>()
|
||||
.ForMember(x => x.Account, o => o.MapFrom(x => x.Account!.Name))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <see cref="MyOffice.Data.Models.Accounts.AccountAccountCategory"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
|
||||
public class AccountAccountCategoryDto
|
||||
{
|
||||
public Guid CategoryId { get; set; }
|
||||
public AccountCategoryDto? Category { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class AccountAccountCategoryDtoProfile: Profile
|
||||
{
|
||||
public AccountAccountCategoryDtoProfile()
|
||||
{
|
||||
CreateMap<AccountAccountCategory, AccountAccountCategoryDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MyOffice.Services.Account.Domain
|
||||
{
|
||||
public class AccountAdd
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string CurrencyId { get; set; } = null!;
|
||||
public Guid CategoryId { get; set; }
|
||||
public string Type { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MyOffice.Services.Account.Domain
|
||||
{
|
||||
public enum AccountAddStatus
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
category_not_found,
|
||||
currency_not_found,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <see cref="MyOffice.Data.Models.Accounts.AccountCategory"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
|
||||
public class AccountCategoryDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public bool AllowDelete { get; set; }
|
||||
}
|
||||
|
||||
public class AccountCategoryDtoProfile: Profile
|
||||
{
|
||||
public AccountCategoryDtoProfile()
|
||||
{
|
||||
CreateMap<AccountCategory, AccountCategoryDto>()
|
||||
.ForMember(x => x.Id, o => o.MapFrom(x => x.Id))
|
||||
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.Accounts!.Any()))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MyOffice.Services.Account.Domain
|
||||
{
|
||||
public enum AccountCategoryRemoveResult
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
not_found,
|
||||
accounts_exists,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <see cref="MyOffice.Data.Models.Accounts.Account"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
|
||||
public class AccountDetailedDto: IDataModelDto<AccountDetailed>
|
||||
{
|
||||
public AccountDto Account { get; set; } = null!;
|
||||
public decimal TotalPlus { get; set; }
|
||||
public decimal TotalMinus { get; set; }
|
||||
public decimal Rest => TotalPlus - TotalMinus;
|
||||
}
|
||||
|
||||
public class AccountDetailedDtoProfile: Profile
|
||||
{
|
||||
public AccountDetailedDtoProfile()
|
||||
{
|
||||
CreateMap<AccountDetailed, AccountDetailedDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using System;
|
||||
using Data.Models.Accounts;
|
||||
using MyOffice.Services.Currency.Domain;
|
||||
using AutoMapper;
|
||||
using MyOffice.Services.Identity;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Services.Mapper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public class GenerateMappedDtoAttribute: Attribute
|
||||
{
|
||||
public GenerateMappedDtoAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[GenerateMappedDto]
|
||||
public class AccountDto : IDataModelDto<Account>
|
||||
{
|
||||
#region Account properties
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public string CurrencyGlobalId { get; set; } = null!;
|
||||
public CurrencyGlobalDto? CurrencyGlobal { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public Guid OwnerId { get; set; }
|
||||
public UserDto? Owner { get; set; }
|
||||
|
||||
#endregion Account properties
|
||||
|
||||
#region Dto properties
|
||||
|
||||
public Guid CurrencyId { get; set; }
|
||||
public CurrencyDto? Currency { get; set; }
|
||||
public string Type { get; set; } = null!;
|
||||
public List<AccountAccountCategoryDto>? Categories { get; set; }
|
||||
|
||||
public bool HasMotions { get; set; }
|
||||
|
||||
#endregion Dto properties
|
||||
|
||||
#region Permissions
|
||||
|
||||
public List<AccountAccessDto>? 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 class AccountDtoProfile : BaseProfile<Account, AccountDto>
|
||||
{
|
||||
public AccountDtoProfile()
|
||||
{
|
||||
Mapping
|
||||
.ForMember(x => x.HasMotions, o => o.MapFrom(x => x.Motions!.Any()))
|
||||
.AfterMap<AccountDtoMappingAction>();
|
||||
}
|
||||
}
|
||||
|
||||
public class AccountDtoMappingAction : BaseMappingAction, IMappingAction<Account, AccountDto>
|
||||
{
|
||||
public AccountDtoMappingAction(IContextProvider contextProvider) : base(contextProvider) { }
|
||||
|
||||
public void Process(Account source, AccountDto destination, ResolutionContext context)
|
||||
{
|
||||
var accessRight = destination.AccessRights?.FirstOrDefault(x => x.UserId == ContextProvider.UserId);
|
||||
destination.AllowRead = accessRight?.IsAllowRead ?? false;
|
||||
destination.AllowWrite = accessRight?.IsAllowWrite ?? false;
|
||||
destination.AllowManage = accessRight?.IsAllowManage ?? false;
|
||||
destination.AllowDelete = (accessRight?.IsOwner ?? false) && !destination.HasMotions;
|
||||
destination.Name = accessRight?.Name ?? destination.Name;
|
||||
destination.Type = accessRight != null ? accessRight.Type.ToString() : destination.Type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public class AccountEdit
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string CurrencyId { get; set; } = null!;
|
||||
public Guid? CategoryId { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public string? Type { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public enum AccountEditStatus
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
not_found,
|
||||
category_not_found,
|
||||
currency_not_found,
|
||||
forbidden,
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MyOffice.Services.Account.Domain
|
||||
{
|
||||
public enum InviteAcceptStatus
|
||||
{
|
||||
success,
|
||||
invite_not_found,
|
||||
account_not_found,
|
||||
already_accepted,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/// <see cref="MyOffice.Data.Models.Items.ItemCategory"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
public class ItemCategoryDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public UserDto User { get; set; } = null!;
|
||||
public string Name { get; set; } = null!;
|
||||
public List<ItemDto> Items { get; set; } = null!;
|
||||
public bool IsInternal { get; set; }
|
||||
}
|
||||
|
||||
public class ItemCategoryDtoProfile: Profile
|
||||
{
|
||||
public ItemCategoryDtoProfile()
|
||||
{
|
||||
CreateMap<ItemCategory, ItemCategoryDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/// <see cref="MyOffice.Data.Models.Items.Item"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
public class ItemDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public bool AllowDelete { get; set; }
|
||||
|
||||
public Guid CategoryId { get; set; }
|
||||
public ItemCategoryDto? Category { get; set; }
|
||||
}
|
||||
|
||||
public class ItemDtoProfile: Profile
|
||||
{
|
||||
public ItemDtoProfile()
|
||||
{
|
||||
CreateMap<Item, ItemDto>()
|
||||
.ForMember(x => x.Id, o => o.MapFrom(x => x.ItemGlobalId))
|
||||
.ForMember(x => x.Name, o => o.MapFrom(x => x.ItemGlobal.Name))
|
||||
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.Motions!.Any()))
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public enum MotionAddStatus
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
account_not_found,
|
||||
forbidden,
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
public class MotionAddUpdate
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public string Item { get; set; } = null!;
|
||||
public string? ItemId { get; set; } = null!;
|
||||
public string? AccountId { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal Plus { get; set; }
|
||||
public decimal Minus { get; set; }
|
||||
public decimal AmountBalancing { get; set; }
|
||||
}
|
||||
|
||||
public class MotionAddUpdateProfile: Profile
|
||||
{
|
||||
public MotionAddUpdateProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public enum MotionDeleteStatus
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
not_found,
|
||||
forbidden,
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
|
||||
public class MotionDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public DateTime CreatedOn { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public Guid AccountId { get; set; }
|
||||
public AccountDto Account { get; set; } = null!;
|
||||
public int ItemId { get; set; }
|
||||
public ItemDto Item { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal AmountPlus { get; set; }
|
||||
public decimal AmountMinus { get; set; }
|
||||
public DateTime? DeletedOn { get; set; }
|
||||
}
|
||||
|
||||
public class MotionDtoProfile: Profile
|
||||
{
|
||||
public MotionDtoProfile()
|
||||
{
|
||||
CreateMap<Motion, MotionDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
public enum MotionUpdateStatus
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
not_found,
|
||||
forbidden,
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/// <see cref="MyOffice.Data.Models.Users.User"/>
|
||||
namespace MyOffice.Services.Account.Domain;
|
||||
|
||||
using AutoMapper;
|
||||
using MyOffice.Data.Models.Users;
|
||||
using MyOffice.Services.Currency.Domain;
|
||||
|
||||
public class UserDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string UserName { get; set; } = null!;
|
||||
public string Email { get; set; } = null!;
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Phone { get; set; }
|
||||
|
||||
public string CurrencyId { get; set; } = null!;
|
||||
public CurrencyGlobalDto? Currency { get; set; }
|
||||
}
|
||||
|
||||
public class UserDtoProfile : Profile
|
||||
{
|
||||
public UserDtoProfile()
|
||||
{
|
||||
CreateMap<User, UserDto>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user