using DigitalData.Core.Infrastructure; using DigitalData.UserManager.Infrastructure.Repositories; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.EntityFrameworkCore; namespace EnvelopeGenerator.Infrastructure.Repositories { public class EnvelopeHistoryRepository : CRUDRepository, IEnvelopeHistoryRepository { public EnvelopeHistoryRepository(EGDbContext dbContext) : base(dbContext) { } private IQueryable By(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = false) { var query = _dbSet.AsQueryable(); if (envelopeId is not null) query = query.Where(eh => eh.EnvelopeId == envelopeId); if (userReference is not null) query = query.Where(eh => eh.UserReference == userReference); if (status is not null) query = query.Where(eh => eh.Status == status); if(withReceiver) query = query.Include(eh => eh.Receiver); string qSt = query.ToQueryString(); return query; } public async Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By( envelopeId: envelopeId, userReference: userReference, status: status).CountAsync(); public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = true) => await By( envelopeId: envelopeId, userReference: userReference, status: status, withReceiver: withReceiver).ToListAsync(); } }