This commit is contained in:
2023-07-31 08:50:05 +03:00
parent cca943f37d
commit c5d9ae7b93
49 changed files with 546 additions and 398 deletions
+30 -30
View File
@@ -1,20 +1,19 @@
namespace MyOffice.Services.Account
{
using AutoMapper;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using Identity;
using Core;
using Core.Extensions;
using Core.Helpers;
using Data.Models.Accounts;
using Data.Models.Items;
using Data.Repositories.Account;
using Data.Repositories.Currency;
using Data.Repositories.Item;
using Domain;
using Item;
using Item.Domain;
using Microsoft.Extensions.Logging;
using MyOffice.Services.Account.Domain;
using System.Collections.Generic;
using Identity;
public class AccountService
{
@@ -84,15 +83,19 @@
return result.Set(_mapper.Map<AccountCategoryDto>(category));
}
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryAdd(Guid userId, AccountCategory category)
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryAdd(Guid userId, AccountCategoryDto input)
{
if (category == null)
throw new ArgumentNullException(nameof(category));
if (input == null)
throw new ArgumentNullException(nameof(input));
var result = new Exec<AccountCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
category.Id = Guid.NewGuid();
category.UserId = userId;
var category = new AccountCategory
{
Id = Guid.NewGuid(),
UserId = userId,
Name = input.Name,
};
if (!_accountCategoryRepository.Add(category))
{
@@ -102,10 +105,10 @@
return result.Set(_mapper.Map<AccountCategoryDto>(category));
}
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, AccountCategory category)
public Exec<AccountCategoryDto, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, AccountCategoryDto input)
{
if (category == null)
throw new ArgumentNullException(nameof(category));
if (input == null)
throw new ArgumentNullException(nameof(input));
var result = new Exec<AccountCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
@@ -115,7 +118,7 @@
return result.Set(GeneralExecStatus.not_found);
}
exists.Name = category.Name;
exists.Name = input.Name;
if (!_accountCategoryRepository.Update(exists))
{
@@ -300,14 +303,11 @@
if (category != null && account.Categories!.All(x => x.CategoryId != category.Id))
{
account.Categories = new List<AccountAccountCategory>
_accountAccountCategoryRepository.Add(new AccountAccountCategory
{
new()
{
AccountId = account.Id,
CategoryId = category.Id,
}
};
AccountId = account.Id,
CategoryId = category.Id,
});
}
if (!_accountRepository.Update(account))
@@ -346,7 +346,7 @@
return result.Set(categories);
}
public Exec<List<Motion>, MotionAddStatus> MotionAdd(
public Exec<List<MotionDto>, MotionAddStatus> MotionAdd(
Guid userId,
Guid accountId,
MotionAddUpdate motion
@@ -357,7 +357,7 @@
if (motion.Item == null)
throw new ArgumentNullException(nameof(motion.Item));
var result = new Exec<List<Motion>, MotionAddStatus>(MotionAddStatus.success);
var result = new Exec<List<MotionDto>, MotionAddStatus>(MotionAddStatus.success);
var account = _accountRepository.Get(userId, accountId);
if (account == null)
@@ -388,8 +388,8 @@
return result.Set(MotionAddStatus.failure);
}
result.Set(new List<Motion>());
result.Result!.Add(motionDb);
result.Set(new List<MotionDto>());
result.Result!.Add(_mapper.Map<MotionDto>(motionDb));
if (motion.AccountId.IsPresent() && motion.AmountBalancing != 0)
{
@@ -419,7 +419,7 @@
if (_motionRepository.Add(motionBalancing))
{
result.Result!.Add(motionBalancing);
result.Result!.Add(_mapper.Map<MotionDto>(motionBalancing));
}
}
}
@@ -429,7 +429,7 @@
return result;
}
public Exec<Motion, MotionUpdateStatus> MotionUpdate(
public Exec<MotionDto, MotionUpdateStatus> MotionUpdate(
Guid userId,
Guid accountId,
Guid motionId,
@@ -441,7 +441,7 @@
if (motion.Item == null)
throw new ArgumentNullException(nameof(motion.Item));
var result = new Exec<Motion, MotionUpdateStatus>(MotionUpdateStatus.success);
var result = new Exec<MotionDto, MotionUpdateStatus>(MotionUpdateStatus.success);
var exists = _motionRepository.Get(userId, motionId);
if (exists == null || exists.AccountId != accountId)
@@ -467,7 +467,7 @@
}
return result.Set(exists);
return result.Set(_mapper.Map<MotionDto>(exists));
}
public Exec<List<Motion>, GeneralExecStatus> GetMotions(
@@ -0,0 +1,14 @@
namespace MyOffice.Services.Account.Domain;
using MyOffice.Data.Models.Users;
public class ItemCategoryDto
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public User User { get; set; } = null!;
public string Name { get; set; } = null!;
public List<ItemDto> Items { get; set; } = null!;
public bool IsInternal { get; set; }
}
@@ -0,0 +1,13 @@
namespace MyOffice.Services.Account.Domain;
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; }
}
@@ -0,0 +1,16 @@
namespace MyOffice.Services.Account.Domain;
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; }
}