This commit is contained in:
2023-06-21 17:56:00 +03:00
parent fa8852a32a
commit e9d4053e65
55 changed files with 3883 additions and 262 deletions
@@ -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);
@@ -16,7 +16,10 @@ public class CurrencyRepository : AppRepository<Currency>, ICurrencyRepository
public Currency? Get(Guid userId, Guid id)
{
return _context.Currencies.FirstOrDefault(x => x.Id == id && x.UserId == userId);
return _context
.Currencies
.Include(x => x.CurrencyGlobal)
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
}
public Currency? GetByGlobalCurrency(Guid userId, string globalCurrencyId)