fix
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Accounts;
|
||||
|
||||
public class AccountAccountCategoryRepository : AppRepository<AccountAccountCategory>, IAccountAccountCategoryRepository
|
||||
{
|
||||
public List<AccountAccountCategory> Get(Guid userId, Guid accountId, Guid categoryId)
|
||||
{
|
||||
return _context.AccountAccountCategories
|
||||
.Include(x => x.Account)
|
||||
.Include(x => x.Category)
|
||||
.Where(x => x.AccountId == accountId && x.CategoryId == categoryId && x.Category.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Remove(AccountAccountCategory accountAccountCategory)
|
||||
{
|
||||
return RemoveBase(accountAccountCategory) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Accounts;
|
||||
using MyOffice.Data.Repositories;
|
||||
|
||||
public class AccountCategoryRepository : AppRepository<AccountCategory>, IAccountCategoryRepository
|
||||
{
|
||||
public List<AccountCategory> GetAll(Guid userId)
|
||||
{
|
||||
return _context.AccountCategories
|
||||
.Include(x => x.Accounts)
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Add(AccountCategory accountCategory)
|
||||
{
|
||||
return AddBase(accountCategory) > 0;
|
||||
}
|
||||
|
||||
public AccountCategory? Get(Guid userId, Guid id)
|
||||
{
|
||||
return _context.AccountCategories
|
||||
.Include(x => x.Accounts)
|
||||
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
|
||||
}
|
||||
|
||||
public bool Update(AccountCategory accountCategory)
|
||||
{
|
||||
return UpdateBase(accountCategory) > 0;
|
||||
}
|
||||
|
||||
public bool Remove(AccountCategory accountCategory)
|
||||
{
|
||||
return RemoveBase(accountCategory) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public class AccountMotionRepository : AppRepository<AccountMotion>, IAccountMotionRepository
|
||||
{
|
||||
public bool Add(AccountMotion accountMotion)
|
||||
{
|
||||
return AddBase(accountMotion) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Accounts;
|
||||
using MyOffice.Data.Repositories;
|
||||
|
||||
public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
{
|
||||
public List<Account> GetAll(Guid userId)
|
||||
{
|
||||
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.AccessRights!.Any(a => a.UserId == userId))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<Account> GetByCategory(Guid userId, Guid categoryId)
|
||||
{
|
||||
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.Categories!.Any(c => c.CategoryId == categoryId) && x.AccessRights!.Any(a => a.UserId == userId))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<AccountDetailed> GetByCategoryDetailed(Guid userId, Guid categoryId)
|
||||
{
|
||||
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.Categories!.Any(c => c.CategoryId == categoryId) && 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.AmountPlus),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Add(Account account)
|
||||
{
|
||||
return AddBase(account) > 0;
|
||||
}
|
||||
|
||||
public Account? Get(Guid userId, Guid id)
|
||||
{
|
||||
return _context.Accounts!
|
||||
.Include(x => x.Categories)!
|
||||
.ThenInclude(x => x.Category)
|
||||
.Include(x => x.AccessRights)!
|
||||
.ThenInclude(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == id && x.AccessRights!.Any(r => r.UserId == userId));
|
||||
}
|
||||
|
||||
public bool Update(Account account)
|
||||
{
|
||||
return UpdateBase(account) > 0;
|
||||
}
|
||||
|
||||
public bool Remove(Account account)
|
||||
{
|
||||
return RemoveBase(account) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IAccountAccountCategoryRepository
|
||||
{
|
||||
List<AccountAccountCategory> Get(Guid userId, Guid accountId, Guid categoryId);
|
||||
bool Remove(AccountAccountCategory accountAccountCategory);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IAccountCategoryRepository
|
||||
{
|
||||
List<AccountCategory> GetAll(Guid userId);
|
||||
bool Add(AccountCategory accountCategory);
|
||||
AccountCategory? Get(Guid userId, Guid id);
|
||||
bool Update(AccountCategory accountCategory);
|
||||
bool Remove(AccountCategory accountCategory);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IAccountMotionRepository
|
||||
{
|
||||
bool Add(AccountMotion accountMotion);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IAccountRepository
|
||||
{
|
||||
List<Account> GetAll(Guid userId);
|
||||
List<Account> GetByCategory(Guid userId, Guid categoryId);
|
||||
List<AccountDetailed> GetByCategoryDetailed(Guid userId, Guid categoryId);
|
||||
bool Add(Account account);
|
||||
Account? Get(Guid userId, Guid id);
|
||||
bool Update(Account account);
|
||||
bool Remove(Account account);
|
||||
}
|
||||
Reference in New Issue
Block a user