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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user