using Distribution.Data; using Distribution.Models; using Microsoft.EntityFrameworkCore; namespace Distribution.Features.ReceivedCheque; public class ReceivedChequeRepository(AppDBContext context) : IReceivedChequeRepository { public async Task GetByIdAsync(Guid id) => await context.ReceivedCheques.FirstOrDefaultAsync(c => c.Id == id); public async Task<(List Items, int TotalCount)> ListAsync( int? companyId, int? branchId, ReceivedChequeStatus? status, ReceivedFromType? receivedFromType, int page, int pageSize) { var query = context.ReceivedCheques.AsQueryable(); if (companyId is not null) query = query.Where(c => c.CompanyId == companyId); if (branchId is not null) query = query.Where(c => c.BranchId == branchId); if (status is not null) query = query.Where(c => c.Status == status); if (receivedFromType is not null) query = query.Where(c => c.ReceivedFromType == receivedFromType); var total = await query.CountAsync(); var items = await query .OrderByDescending(c => c.ReceivedDate) .Skip((page - 1) * pageSize) .Take(pageSize) .ToListAsync(); return (items, total); } public async Task AddAsync(Models.ReceivedCheque cheque) => await context.ReceivedCheques.AddAsync(cheque); public void Update(Models.ReceivedCheque cheque) => context.ReceivedCheques.Update(cheque); }