fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
namespace MyOffice.Services.Account
|
||||
{
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Core.Helpers;
|
||||
using Data.Models.Accounts;
|
||||
using Data.Models.Motions;
|
||||
@@ -47,6 +48,20 @@
|
||||
return _accountCategoryRepository.GetAll(userId);
|
||||
}
|
||||
|
||||
public Exec<AccountCategory, GeneralExecStatus> GetCategory(Guid userId, Guid id)
|
||||
{
|
||||
var result = new Exec<AccountCategory, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var category = _accountCategoryRepository.Get(userId, id);
|
||||
|
||||
if (category == null)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
return result.Set(category);
|
||||
}
|
||||
|
||||
public Exec<AccountCategory, GeneralExecStatus> CategoryAdd(Guid userId, AccountCategory category)
|
||||
{
|
||||
if (category == null)
|
||||
@@ -125,6 +140,19 @@
|
||||
return _accountRepository.GetByCategoryDetailed(userId, categoryId);
|
||||
}
|
||||
|
||||
public Exec<AccountDetailed, GeneralExecStatus> GetByIdDetailed(Guid userId, Guid id)
|
||||
{
|
||||
var result = new Exec<AccountDetailed, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var account = _accountRepository.GetByIdDetailed(userId, id);
|
||||
if (account == null)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
return result.Set(account);
|
||||
}
|
||||
|
||||
public Exec<Account, AccountAddResult> AccountAdd(Guid userId, AccountAdd input)
|
||||
{
|
||||
if (input == null)
|
||||
@@ -270,33 +298,36 @@
|
||||
return result.Set(AccountMotionAddResult.account_not_found);
|
||||
}
|
||||
|
||||
var motion = _motionGlobalRepository.GetByName(accountMotion.Motion);
|
||||
if (motion == null)
|
||||
var motionGlobal = _motionGlobalRepository.GetByName(accountMotion.Motion);
|
||||
if (motionGlobal == null)
|
||||
{
|
||||
motion = new MotionGlobal
|
||||
// add global motion
|
||||
motionGlobal = new MotionGlobal
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = accountMotion.Motion.Trim(),
|
||||
};
|
||||
if (_motionGlobalRepository.Add(motion))
|
||||
if (!_motionGlobalRepository.Add(motionGlobal))
|
||||
{
|
||||
return result.Set(AccountMotionAddResult.failure);
|
||||
}
|
||||
}
|
||||
|
||||
var motionAccount = _motionRepository.GetByGlobal(userId, motion.Id);
|
||||
var motionAccount = _motionRepository.GetByGlobal(userId, motionGlobal.Id);
|
||||
if (motionAccount == null)
|
||||
{
|
||||
// add motion account
|
||||
motionAccount = new MotionAccount
|
||||
{
|
||||
CategoryId = userId,
|
||||
MotionGlobalId = motion.Id,
|
||||
MotionGlobalId = motionGlobal.Id,
|
||||
};
|
||||
_motionRepository.Add(motionAccount);
|
||||
}
|
||||
|
||||
var accountMotionDb = new AccountMotion
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CreatedOn = DateTime.UtcNow,
|
||||
DateTime = accountMotion.Date,
|
||||
AccountId = account.Id,
|
||||
@@ -312,7 +343,28 @@
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
motionAccount.MotionGlobal = motionGlobal;
|
||||
accountMotionDb.Motion = motionAccount;
|
||||
|
||||
return result.Set(accountMotionDb);
|
||||
}
|
||||
|
||||
public Exec<List<AccountMotion>, GeneralExecStatus> GetAccountMotion(
|
||||
Guid userId,
|
||||
Guid accountId,
|
||||
DateTime dateFrom,
|
||||
DateTime dateTo
|
||||
)
|
||||
{
|
||||
var result = new Exec<List<AccountMotion>, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var account = _accountRepository.Get(userId, accountId);
|
||||
if (account == null)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
return result.Set(_accountMotionRepository.GetByAccount(accountId, dateFrom.ToUtc(), dateTo.ToUtc()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,30 +41,58 @@ public class CurrencyService
|
||||
);
|
||||
}
|
||||
|
||||
public Exec<Currency, AddCurrencyStatus> AddCurrency(Guid userId, Currency currency)
|
||||
public Exec<Currency, CurrencyAddStatus> CurrencyAdd(Guid userId, Currency currency)
|
||||
{
|
||||
if (currency == null)
|
||||
throw new ArgumentNullException(nameof(currency));
|
||||
|
||||
var result = new Exec<Currency, AddCurrencyStatus>(AddCurrencyStatus.success);
|
||||
var result = new Exec<Currency, CurrencyAddStatus>(CurrencyAddStatus.success);
|
||||
|
||||
var exists = _currencyRepository.GetByGlobalCurrency(userId, currency.CurrencyGlobalId);
|
||||
if (exists != null)
|
||||
{
|
||||
return result.Set(exists, AddCurrencyStatus.exists);
|
||||
return result.Set(exists, CurrencyAddStatus.exists);
|
||||
}
|
||||
|
||||
currency.Id = Guid.NewGuid();
|
||||
currency.UserId = userId;
|
||||
if (!_currencyRepository.Add(currency))
|
||||
{
|
||||
return result.Set(AddCurrencyStatus.failed);
|
||||
return result.Set(CurrencyAddStatus.failed);
|
||||
}
|
||||
|
||||
return result.Set(currency);
|
||||
}
|
||||
|
||||
public Exec<CurrencyRate, CurrencyAddRateStatus> AddCurrencyRate(Guid userId, Guid currencyId, CurrencyRate currencyRate)
|
||||
public Exec<Currency, CurrencyEditStatus> CurrencyUpdate(
|
||||
Guid userId,
|
||||
Guid currencyId,
|
||||
CurrencyEdit currency
|
||||
)
|
||||
{
|
||||
if (currency == null)
|
||||
throw new ArgumentNullException(nameof(currency));
|
||||
|
||||
var result = new Exec<Currency, CurrencyEditStatus>(CurrencyEditStatus.success);
|
||||
|
||||
var exists = _currencyRepository.Get(userId, currencyId);
|
||||
if (exists == null)
|
||||
{
|
||||
return result.Set(CurrencyEditStatus.not_found);
|
||||
}
|
||||
|
||||
exists.Name = currency.Name;
|
||||
exists.ShortName = currency.ShortName;
|
||||
|
||||
if (!_currencyRepository.Update(exists))
|
||||
{
|
||||
return result.Set(CurrencyEditStatus.failed);
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
}
|
||||
|
||||
public Exec<CurrencyRate, CurrencyAddRateStatus> CurrencyRateAdd(Guid userId, Guid currencyId, CurrencyRate currencyRate)
|
||||
{
|
||||
if (currencyRate == null)
|
||||
throw new ArgumentNullException(nameof(currencyRate));
|
||||
@@ -80,15 +108,18 @@ public class CurrencyService
|
||||
currencyRate.CurrencyId = exists.Id;
|
||||
currencyRate.DateTime = currencyRate.DateTime.Date;
|
||||
|
||||
var rate = _currencyRateRepository.GetAtDate(currencyRate.CurrencyId, currencyRate.DateTime);
|
||||
if (rate.All(x => x.Rate != currencyRate.Rate))
|
||||
var rates = _currencyRateRepository.GetAtDate(currencyRate.CurrencyId, currencyRate.DateTime);
|
||||
var rate = rates.Find(x => x.Rate == currencyRate.Rate);
|
||||
if (rate == null)
|
||||
{
|
||||
if (_currencyRateRepository.AddRate(currencyRate))
|
||||
if (!_currencyRateRepository.AddRate(currencyRate))
|
||||
{
|
||||
return result.Set(currencyRate);
|
||||
return result.Set(CurrencyAddRateStatus.failed);
|
||||
}
|
||||
|
||||
rate = currencyRate;
|
||||
}
|
||||
|
||||
return result.Set(CurrencyAddRateStatus.failed);
|
||||
return result.Set(rate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
namespace MyOffice.Services.Currency.Domain
|
||||
{
|
||||
public enum AddCurrencyStatus
|
||||
{
|
||||
success,
|
||||
failed,
|
||||
exists,
|
||||
}
|
||||
|
||||
public enum CurrencyAddRateStatus
|
||||
{
|
||||
not_found,
|
||||
success,
|
||||
failed,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
public enum CurrencyAddRateStatus
|
||||
{
|
||||
not_found,
|
||||
success,
|
||||
failed,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Services.Currency.Domain
|
||||
{
|
||||
public enum CurrencyAddStatus
|
||||
{
|
||||
success,
|
||||
failed,
|
||||
exists,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
public class CurrencyEdit
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string ShortName { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MyOffice.Services.Currency.Domain;
|
||||
|
||||
public enum CurrencyEditStatus
|
||||
{
|
||||
success,
|
||||
not_found,
|
||||
failed,
|
||||
}
|
||||
Reference in New Issue
Block a user