This commit is contained in:
2023-07-25 22:10:03 +03:00
parent ce2ae68c9f
commit 5ecefe5756
30 changed files with 2321 additions and 123 deletions
+39 -4
View File
@@ -332,7 +332,7 @@
return result.Set(categories);
}
public Exec<Motion, MotionAddResult> MotionAdd(
public Exec<List<Motion>, MotionAddResult> MotionAdd(
Guid userId,
Guid accountId,
MotionAddUpdate motion
@@ -343,7 +343,7 @@
if (motion.Item == null)
throw new ArgumentNullException(nameof(motion.Item));
var result = new Exec<Motion, MotionAddResult>(MotionAddResult.success);
var result = new Exec<List<Motion>, MotionAddResult>(MotionAddResult.success);
var account = _accountRepository.Get(userId, accountId);
if (account == null)
@@ -364,20 +364,55 @@
DateTime = motion.Date,
AccountId = account.Id,
ItemId = itemExec.Result!.Id,
Description = motion.Description,
AmountPlus = motion.Plus,
AmountMinus = motion.Minus,
Description = motion.Description,
};
if (!_motionRepository.Add(motionDb))
{
return result.Set(MotionAddResult.failure);
}
result.Set(new List<Motion>());
result.Result!.Add(motionDb);
if (motion.AccountId.IsPresent() && motion.AmountBalancing != 0)
{
var accountBalancing = _accountRepository.Get(userId, motion.AccountId!.AsGuid());
if (accountBalancing != null)
{
var balancingName = $"+{account.Name}";
var itemBalancingExec = _itemService.GetOrCreate(userId, balancingName);
var plus = motion.AmountBalancing;
var minus = 0m;
if (motion.Plus != 0)
{
plus = 0;
minus = motion.AmountBalancing;
}
var motionBalancing = new Motion
{
Id = Guid.NewGuid(),
CreatedOn = DateTime.UtcNow,
DateTime = motion.Date,
AccountId = accountBalancing.Id,
ItemId = itemBalancingExec.Result!.Id,
Description = motion.Description,
AmountPlus = plus,
AmountMinus = minus,
};
if (_motionRepository.Add(motionBalancing))
{
result.Result!.Add(motionBalancing);
}
}
}
motionDb.Item = itemExec.Result!;
return result.Set(motionDb);
return result;
}
public Exec<Motion, MotionUpdateResult> MotionUpdate(
@@ -0,0 +1,30 @@
using MyOffice.Services.Account.Domain;
namespace MyOffice.Services.Account;
using AutoMapper;
using Data.Models.Accounts;
using Data.Models.Users;
public class AccountServiceProfile : Profile
{
public AccountServiceProfile()
{
CreateMap<User, UserDto>();
CreateMap<Account, AccountDto>()
.ForMember(x => x.HasMotions, o => o.MapFrom(x => x.Motions.Any()))
;
CreateMap<AccountDetailed, AccountDetailedDto>();
CreateMap<AccountAccess, AccountAccessDto>();
CreateMap<AccountAccountCategory, AccountAccountCategoryDto>();
CreateMap<AccountCategory, AccountCategoryDto>()
.ForMember(x => x.Id, o => o.MapFrom(x => x.Id))
.ForMember(x => x.Id, o => o.MapFrom(x => x.Id))
;
}
}
@@ -0,0 +1,17 @@
namespace MyOffice.Services.Account.Domain;
using Data.Models.Accounts;
using Data.Models.Users;
public class AccountAccessDto
{
public Guid AccountId { get; set; }
public AccountDto? Account { get; set; }
public Guid UserId { get; set; }
public User? User { get; set; }
public bool IsAllowRead { get; set; }
public bool IsAllowWrite { get; set; }
public bool IsAllowManage { get; set; }
public AccountAccessTypeEnum Type { get; set; }
}
@@ -0,0 +1,7 @@
namespace MyOffice.Services.Account.Domain;
public class AccountAccountCategoryDto
{
public Guid CategoryId { get; set; }
public AccountCategoryDto? Category { get; set; } = null!;
}
@@ -0,0 +1,6 @@
public class AccountCategoryDto
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Name { get; set; } = null!;
}
+1 -71
View File
@@ -1,13 +1,6 @@
using MyOffice.Data.Models.Accounts;
using MyOffice.Data.Models.Users;
using MyOffice.Services.Account.Domain;
namespace MyOffice.Services.Account.Domain
namespace MyOffice.Services.Account.Domain
{
using AutoMapper;
using MyOffice.Data.Models.Accounts;
using MyOffice.Data.Models.Currencies;
using MyOffice.Data.Models.Users;
using System;
public class AccountDto
@@ -26,67 +19,4 @@ namespace MyOffice.Services.Account.Domain
public List<AccountAccessDto>? AccessRights { get; set; }
public List<AccountAccountCategoryDto>? Categories { get; set; }
}
public class AccountAccessDto
{
public Guid AccountId { get; set; }
public AccountDto? Account { get; set; }
public Guid UserId { get; set; }
public User? User { get; set; }
public bool IsAllowRead { get; set; }
public bool IsAllowWrite { get; set; }
public bool IsAllowManage { get; set; }
public AccountAccessTypeEnum Type { get; set; }
}
public class AccountAccountCategoryDto
{
public Guid CategoryId { get; set; }
public AccountCategoryDto? Category { get; set; } = null!;
}
public class AccountMappingProfile : Profile
{
public AccountMappingProfile()
{
CreateMap<User, UserDto>();
CreateMap<Account, AccountDto>()
.ForMember(x => x.HasMotions, o => o.MapFrom(x => x.Motions.Any()))
;
CreateMap<AccountDetailed, AccountDetailedDto>();
CreateMap<AccountAccess, AccountAccessDto>();
CreateMap<AccountAccountCategory, AccountAccountCategoryDto>();
CreateMap<AccountCategory, AccountCategoryDto>()
.ForMember(x => x.Id, o => o.MapFrom(x => x.Id))
.ForMember(x => x.Id, o => o.MapFrom(x => x.Id))
;
}
}
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; }
public CurrencyGlobal? Currency { get; set; }
}
}
public class AccountCategoryDto
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Name { get; set; } = null!;
}
@@ -4,8 +4,11 @@
{
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; }
}
}
@@ -0,0 +1,17 @@
namespace MyOffice.Services.Account.Domain;
using Data.Models.Currencies;
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; }
public CurrencyGlobal? Currency { get; set; }
}