Files

74 lines
2.1 KiB
C#

namespace MyOffice.Data.Repositories.Account;
using Microsoft.EntityFrameworkCore;
using Models.Accounts;
using MyOffice.Data.Repositories;
using MyOffice.DbContext;
public class AccountCategoryRepository : AppRepository<AccountCategory>, IAccountCategoryRepository
{
public AccountCategoryRepository(AppDbContext context) : base(context)
{
}
public List<AccountCategory> GetAll(Guid userId)
{
return _context.AccountCategories
.Include(x => x.Accounts)
.Where(x => x.UserId == userId)
.ToList();
}
public async Task<List<AccountCategory>> GetAllAsync(Guid userId, CancellationToken cancellationToken = default)
{
return await _context.AccountCategories
.Include(x => x.Accounts)
.Where(x => x.UserId == userId)
.ToListAsync(cancellationToken);
}
public bool Add(AccountCategory accountCategory)
{
return AddBase(accountCategory) > 0;
}
public async Task<bool> AddAsync(AccountCategory accountCategory, CancellationToken cancellationToken = default)
{
return await AddBaseAsync(accountCategory, cancellationToken) > 0;
}
public AccountCategory? Get(Guid userId, Guid id)
{
return _context.AccountCategories
.Include(x => x.Accounts)
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
}
public async Task<AccountCategory?> GetAsync(Guid userId, Guid id, CancellationToken cancellationToken = default)
{
return await _context.AccountCategories
.Include(x => x.Accounts)
.FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, cancellationToken);
}
public bool Update(AccountCategory accountCategory)
{
return UpdateBase(accountCategory) > 0;
}
public async Task<bool> UpdateAsync(AccountCategory accountCategory, CancellationToken cancellationToken = default)
{
return await UpdateBaseAsync(accountCategory, cancellationToken) > 0;
}
public bool Remove(AccountCategory accountCategory)
{
return RemoveBase(accountCategory) > 0;
}
public async Task<bool> RemoveAsync(AccountCategory accountCategory, CancellationToken cancellationToken = default)
{
return await RemoveBaseAsync(accountCategory, cancellationToken) > 0;
}
}