using DigitalData.Core.Infrastructure; using EnvelopeGenerator.Domain.Entities; using Microsoft.EntityFrameworkCore; using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Application.Common.Interfaces.Repositories; namespace EnvelopeGenerator.Infrastructure.Repositories; [Obsolete("Use TempRepo")] public class EnvelopeHistoryRepository : CRUDRepository, IEnvelopeHistoryRepository { public EnvelopeHistoryRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeHistories) { } private IQueryable By(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false) { var query = _dbSet.AsNoTracking(); 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 (withSender) query = query.Include(eh => eh.Sender); if (withReceiver) query = query.Include(eh => eh.Receiver); return query; } public async Task CountAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null) => await By( envelopeId: envelopeId, userReference: userReference, status: status).CountAsync(); public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false) => await By( envelopeId: envelopeId, userReference: userReference, status: status, withSender: withSender, withReceiver: withReceiver).ToListAsync(); }