56 lines
2.1 KiB
C#
56 lines
2.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 EnvelopeRepository : CRUDRepository<Envelope, int, EGDbContext>, IEnvelopeRepository
|
|
{
|
|
public EnvelopeRepository(EGDbContext dbContext) : base(dbContext)
|
|
{
|
|
}
|
|
|
|
public async Task<IEnumerable<Envelope>> ReadAllWithAsync(bool documents = false, bool receivers = false, bool history = false, bool documentReceiverElement = false)
|
|
{
|
|
var query = _dbSet.AsQueryable();
|
|
|
|
if (documents)
|
|
if (documentReceiverElement)
|
|
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
|
|
else
|
|
query = query.Include(e => e.Documents);
|
|
|
|
if (receivers)
|
|
query = query.Include(e => e.Receivers);
|
|
|
|
if (history)
|
|
query = query.Include(e => e.History);
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
public async Task<Envelope?> ReadByUuidAsync(string uuid, string? signature = null, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false)
|
|
{
|
|
var query = _dbSet.Where(e => e.Uuid == uuid);
|
|
|
|
if (signature is not null)
|
|
query = query.Where(e => e.Receivers != null && e.Receivers.Any(er => er.Receiver != null && er.Receiver.Signature == signature));
|
|
|
|
if (withDocuments)
|
|
if (withDocumentReceiverElement)
|
|
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
|
|
else
|
|
query = query.Include(e => e.Documents);
|
|
|
|
if (withReceivers)
|
|
query = query.Include(e => e.Receivers!).ThenInclude(er => er.Receiver);
|
|
|
|
if (withHistory)
|
|
query = query.Include(e => e.History);
|
|
|
|
return await query.FirstOrDefaultAsync();
|
|
}
|
|
}
|
|
} |