using DigitalData.Core.Exceptions; using EnvelopeGenerator.Application.Interfaces.Model; using EnvelopeGenerator.Application.Model; using EnvelopeGenerator.Domain.Interfaces; namespace EnvelopeGenerator.Application.Extensions; /// /// /// public static class QueryExtensions { /// /// /// /// /// /// /// /// /// /// public static IQueryable Where(this IQueryable root, IHasEnvelopeQuery query, bool notnull = true) where TEntity : IHasEnvelope where TEnvelopeQuery : EnvelopeQueryBase { if (query.Envelope.Id is not null) root = root.Where(e => e.Envelope!.Id == query.Envelope.Id); else if (query.Envelope.Uuid is not null) root = root.Where(e => e.Envelope!.Uuid == query.Envelope.Uuid); else if (notnull) throw new BadRequestException( "Either Envelope Id or Envelope Uuid must be provided in the query." ); return root; } /// /// /// /// /// /// /// /// /// /// public static IQueryable Where(this IQueryable root, IHasReceiverQuery query, bool notnull = true) where TEntity : IHasReceiver where TReceiverQueryBase : ReceiverQueryBase { if (query.Receiver.Id is not null) root = root.Where(e => e.Receiver!.Id == query.Receiver.Id); else if (query.Receiver.EmailAddress is not null) root = root.Where(e => e.Receiver!.EmailAddress == query.Receiver.EmailAddress); else if (query.Receiver.Signature is not null) root = root.Where(e => e.Receiver!.Signature == query.Receiver.Signature); else if (notnull) throw new BadRequestException( "Receiver must have at least one identifier (Id, EmailAddress, or Signature)." ); return root; } }