- `EnvelopeReceiver` in `EnvelopeReceiver` und `EnvelopeReceiverBase` aufgeteilt, um zirkuläre Abhängigkeiten zu vermeiden. - `EnvelopeReceiverBasicDto` für vereinfachte Datenübertragungsobjekte erstellt. - `ReceiverRepository` aktualisiert, um den zuletzt verwendeten Empfängernamen durch das Laden aktueller `EnvelopeReceiver`-Daten einzubeziehen. - `ReceiverReadDto` angepasst, um `LastUsedName` zu erhalten und `EnvelopeReceivers` für die JSON-Serialisierung zu ignorieren.
35 lines
1.4 KiB
C#
35 lines
1.4 KiB
C#
using DigitalData.Core.Infrastructure;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Infrastructure.Contracts;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure.Repositories
|
|
{
|
|
public class ReceiverRepository : CRUDRepository<Receiver, int, EGDbContext>, IReceiverRepository
|
|
{
|
|
public ReceiverRepository(EGDbContext dbContext) : base(dbContext)
|
|
{
|
|
}
|
|
|
|
protected IQueryable<Receiver> ReadBy(string? emailAddress = null, string? signature = null, bool withLastUsedName = true)
|
|
{
|
|
IQueryable<Receiver> query = _dbSet.AsNoTracking();
|
|
|
|
if(emailAddress is not null)
|
|
query = query.Where(r => r.EmailAddress == emailAddress);
|
|
|
|
if(signature is not null)
|
|
query = query.Where(r => r.Signature == signature);
|
|
|
|
// envelope receivers are ignored (with '[JsonIgnore]' attribute). The reson to add them is to get the las used receiver name
|
|
if (withLastUsedName)
|
|
{
|
|
query = query.Include(r => r.EnvelopeReceivers!.OrderByDescending(er => er.EnvelopeId).Take(1));
|
|
}
|
|
|
|
return query;
|
|
}
|
|
|
|
public async Task<Receiver?> ReadByAsync(string? emailAddress = null, string? signature = null) => await ReadBy(emailAddress, signature).FirstOrDefaultAsync();
|
|
}
|
|
} |