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