- `ReadByUsernameAsync` aktualisiert, um optionale Parameter `min_status`, `max_status` und `ignore_statuses` zu unterstützen. - Abfrage optimiert, um Umschläge basierend auf Statuswerten zu filtern. - Ermöglicht das Abrufen von Umschlägen mit spezifischen Statusbereichen oder das Ignorieren bestimmter Status.
80 lines
4.1 KiB
C#
80 lines
4.1 KiB
C#
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 EnvelopeReceiverRepository : CRUDRepository<EnvelopeReceiver, object, EGDbContext>, IEnvelopeReceiverRepository
|
|
{
|
|
public EnvelopeReceiverRepository(EGDbContext dbContext) : base(dbContext)
|
|
{
|
|
}
|
|
|
|
private IQueryable<EnvelopeReceiver> ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false)
|
|
{
|
|
var query = _dbSet.AsNoTracking();
|
|
|
|
if (uuid is not null)
|
|
query = query.Where(er => er.Envelope != null && er.Envelope.Uuid == uuid);
|
|
|
|
if (signature is not null)
|
|
query = query.Where(er => er.Receiver != null && er.Receiver.Signature == signature);
|
|
|
|
if (withEnvelope)
|
|
query = query
|
|
.Include(er => er.Envelope).ThenInclude(e => e!.Documents!).ThenInclude(d => d.Elements!.Where(e => signature == null || e.Receiver!.Signature == signature))
|
|
.Include(er => er.Envelope).ThenInclude(e => e!.History)
|
|
.Include(er => er.Envelope).ThenInclude(e => e!.User);
|
|
|
|
if (withReceiver)
|
|
query = query.Include(er => er.Receiver);
|
|
return query;
|
|
}
|
|
|
|
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false)
|
|
=> await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync();
|
|
|
|
public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true)
|
|
=> await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync();
|
|
|
|
public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true)
|
|
=> await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).FirstOrDefaultAsync();
|
|
|
|
public async Task<string?> ReadAccessCodeAsync(string uuid, string signature)
|
|
=> await ReadWhere(uuid: uuid, signature: signature)
|
|
.Select(er => er.AccessCode)
|
|
.FirstOrDefaultAsync();
|
|
|
|
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
|
|
|
|
public IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId) => _dbSet.AsNoTracking()
|
|
.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
|
|
|
|
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId)
|
|
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId)
|
|
.FirstOrDefaultAsync();
|
|
|
|
public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId)
|
|
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId)
|
|
.Select(er => er.AccessCode)
|
|
.FirstOrDefaultAsync();
|
|
|
|
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
|
|
{
|
|
var query = _dbSet.AsNoTracking().Where(er => er.Envelope!.User!.Username == username);
|
|
|
|
if (min_status is not null)
|
|
query = query.Where(er => er.Envelope!.Status >= min_status);
|
|
|
|
if (max_status is not null)
|
|
query = query.Where(er => er.Envelope!.Status <= max_status);
|
|
|
|
foreach (var ignore_status in ignore_statuses)
|
|
query = query.Where(er => er.Envelope!.Status != ignore_status);
|
|
|
|
return await query.Include(er => er.Envelope).Include(er => er.Receiver).ToListAsync();
|
|
}
|
|
}
|
|
} |