47 lines
1.5 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)
{
var query = _dbSet.AsQueryable();
if (documents)
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, bool withDocuments = false, bool withReceivers = false, bool withHistory = false)
{
var query = _dbSet.Where(e => e.Uuid == uuid);
if (withDocuments)
query = query.Include(e => e.Documents);
if (withReceivers)
query = query.Include(e => e.Receivers);
if (withHistory)
query = query.Include(e => e.History);
return await query.FirstOrDefaultAsync();
}
}
}