fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Accounts;
|
||||
|
||||
public class AccountMotionRepository : AppRepository<AccountMotion>, IAccountMotionRepository
|
||||
@@ -8,4 +9,16 @@ public class AccountMotionRepository : AppRepository<AccountMotion>, IAccountMot
|
||||
{
|
||||
return AddBase(accountMotion) > 0;
|
||||
}
|
||||
|
||||
public List<AccountMotion> GetByAccount(Guid accountId, DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
return _context
|
||||
.AccountMotions
|
||||
.Include(x => x.Motion)
|
||||
.ThenInclude(x => x.MotionGlobal)
|
||||
.Where(x => x.AccountId == accountId && x.DateTime >= dateFrom && x.DateTime <= dateTo)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ThenByDescending(x => x.CreatedOn)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -43,11 +43,29 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
{
|
||||
Account = x,
|
||||
TotalPlus = x.Motions!.Sum(m => m.AmountPlus),
|
||||
TotalMinus = x.Motions!.Sum(m => m.AmountPlus),
|
||||
TotalMinus = x.Motions!.Sum(m => m.AmountMinus),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public AccountDetailed? GetByIdDetailed(Guid userId, Guid id)
|
||||
{
|
||||
return _context.Accounts!
|
||||
.Include(x => x.CurrencyGlobal)
|
||||
.Include(x => x.Categories)!
|
||||
.ThenInclude(x => x.Category)
|
||||
.Include(x => x.AccessRights)!
|
||||
.ThenInclude(x => x.User)
|
||||
.Where(x => x.Id == id && x.AccessRights!.Any(a => a.UserId == userId))
|
||||
.Select(x => new AccountDetailed
|
||||
{
|
||||
Account = x,
|
||||
TotalPlus = x.Motions!.Sum(m => m.AmountPlus),
|
||||
TotalMinus = x.Motions!.Sum(m => m.AmountMinus),
|
||||
})
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool Add(Account account)
|
||||
{
|
||||
return AddBase(account) > 0;
|
||||
|
||||
@@ -5,4 +5,5 @@ using Models.Accounts;
|
||||
public interface IAccountMotionRepository
|
||||
{
|
||||
bool Add(AccountMotion accountMotion);
|
||||
List<AccountMotion> GetByAccount(Guid accountId, DateTime dateFrom, DateTime dateTo);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public interface IAccountRepository
|
||||
List<Account> GetAll(Guid userId);
|
||||
List<Account> GetByCategory(Guid userId, Guid categoryId);
|
||||
List<AccountDetailed> GetByCategoryDetailed(Guid userId, Guid categoryId);
|
||||
AccountDetailed? GetByIdDetailed(Guid userId, Guid id);
|
||||
bool Add(Account account);
|
||||
Account? Get(Guid userId, Guid id);
|
||||
bool Update(Account account);
|
||||
|
||||
Reference in New Issue
Block a user