using Distribution.Data; using Distribution.Models; using Microsoft.EntityFrameworkCore; namespace Distribution.Features.Payment; public class PaymentRepository(AppDBContext context) : IPaymentRepository { public async Task GetByIdAsync(Guid id) => await context.Payments.FirstOrDefaultAsync(p => p.Id == id && p.IsActive); public async Task> GetAllAsync(Guid? invoiceId, int page, int pageSize) => await context.Payments .Where(p => p.IsActive && (invoiceId == null || p.FK_InvoiceId == invoiceId)) .OrderByDescending(p => p.CollectedAt) .Skip((page - 1) * pageSize) .Take(pageSize) .ToListAsync(); public async Task GetCountAsync(Guid? invoiceId) => await context.Payments .CountAsync(p => p.IsActive && (invoiceId == null || p.FK_InvoiceId == invoiceId)); public async Task> GetByInvoiceIdAsync(Guid invoiceId) => await context.Payments .Where(p => p.FK_InvoiceId == invoiceId && p.IsActive) .OrderBy(p => p.CollectedAt) .ToListAsync(); public async Task AddAsync(Models.Payment payment) => await context.Payments.AddAsync(payment); public void Update(Models.Payment payment) => context.Payments.Update(payment); }