refactor: Aktualisierung der Anwendungs- und Infrastrukturebenen, so dass die Infrastruktur von der Anwendung abhängig ist.
- Repository-Schnittstellen wurden in die Anwendungsschicht verschoben. - Erweiterungsmethoden für die Injektion von Repository-Abhängigkeiten wurden in die Infrastruktur verschoben.
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
{
|
||||
public class ConfigRepository : CRUDRepository<Config, int, EGDbContext>, IConfigRepository
|
||||
{
|
||||
public ConfigRepository(EGDbContext dbContext) : base(dbContext, dbContext.Configs)
|
||||
{
|
||||
}
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public async Task<Config?> ReadFirstAsync()
|
||||
{
|
||||
var configs = await _dbSet.ToListAsync();
|
||||
return configs.Count > 0 ? configs[0] : default;
|
||||
}
|
||||
public class ConfigRepository : CRUDRepository<Config, int, EGDbContext>, IConfigRepository
|
||||
{
|
||||
public ConfigRepository(EGDbContext dbContext) : base(dbContext, dbContext.Configs)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<Config?> ReadFirstAsync()
|
||||
{
|
||||
var configs = await _dbSet.ToListAsync();
|
||||
return configs.Count > 0 ? configs[0] : default;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class DocumentReceiverElementRepository : CRUDRepository<DocumentReceiverElement, int, EGDbContext>, IDocumentReceiverElementRepository
|
||||
{
|
||||
public class DocumentReceiverElementRepository : CRUDRepository<DocumentReceiverElement, int, EGDbContext>, IDocumentReceiverElementRepository
|
||||
public DocumentReceiverElementRepository(EGDbContext dbContext) : base(dbContext, dbContext.DocumentReceiverElements)
|
||||
{
|
||||
public DocumentReceiverElementRepository(EGDbContext dbContext) : base(dbContext, dbContext.DocumentReceiverElements)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using DigitalData.UserManager.Infrastructure.Repositories;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class DocumentStatusRepository : CRUDRepository<DocumentStatus, int, EGDbContext>, IDocumentStatusRepository
|
||||
{
|
||||
public class DocumentStatusRepository : CRUDRepository<DocumentStatus, int, EGDbContext>, IDocumentStatusRepository
|
||||
public DocumentStatusRepository(EGDbContext dbContext) : base(dbContext, dbContext.DocumentStatus)
|
||||
{
|
||||
public DocumentStatusRepository(EGDbContext dbContext) : base(dbContext, dbContext.DocumentStatus)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,33 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using static EnvelopeGenerator.Common.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
{
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EmailTemplateRepository : CRUDRepository<EmailTemplate, int, EGDbContext>, IEmailTemplateRepository
|
||||
{
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
public EmailTemplateRepository(EGDbContext dbContext, IMemoryCache cache) : base(dbContext, dbContext.EmailTemplate)
|
||||
public EmailTemplateRepository(EGDbContext dbContext, IMemoryCache cache) : base(dbContext, dbContext.EmailTemplate)
|
||||
{
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
private readonly Guid key_guid = Guid.NewGuid();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an email template based on its name.
|
||||
/// Utilizes in-memory caching to improve performance for the limited number of email templates available.
|
||||
/// If the template is not found in the cache, it queries the database and stores the result in the cache.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the email template, which corresponds to its name.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the email template
|
||||
/// if found, otherwise null.
|
||||
/// </returns>
|
||||
public async Task<EmailTemplate?> ReadByNameAsync(EmailTemplateType type) => await _cache.GetOrCreateAsync($"{type}{key_guid}", async _
|
||||
/// <summary>
|
||||
/// Retrieves an email template based on its name.
|
||||
/// Utilizes in-memory caching to improve performance for the limited number of email templates available.
|
||||
/// If the template is not found in the cache, it queries the database and stores the result in the cache.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the email template, which corresponds to its name.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the email template
|
||||
/// if found, otherwise null.
|
||||
/// </returns>
|
||||
public async Task<EmailTemplate?> ReadByNameAsync(EmailTemplateType type) => await _cache.GetOrCreateAsync($"{type}{key_guid}", async _
|
||||
=> await _dbSet.Where(t => t.Name == type.ToString()).FirstOrDefaultAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeCertificateRepository : CRUDRepository<EnvelopeCertificate, int, EGDbContext>, IEnvelopeCertificateRepository
|
||||
{
|
||||
public class EnvelopeCertificateRepository : CRUDRepository<EnvelopeCertificate, int, EGDbContext>, IEnvelopeCertificateRepository
|
||||
public EnvelopeCertificateRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeCertificates)
|
||||
{
|
||||
public EnvelopeCertificateRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeCertificates)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using DigitalData.UserManager.Infrastructure.Repositories;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeDocumentRepository : CRUDRepository<EnvelopeDocument, int, EGDbContext>, IEnvelopeDocumentRepository
|
||||
{
|
||||
public class EnvelopeDocumentRepository : CRUDRepository<EnvelopeDocument, int, EGDbContext>, IEnvelopeDocumentRepository
|
||||
public EnvelopeDocumentRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeDocument)
|
||||
{
|
||||
public EnvelopeDocumentRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeDocument)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,48 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeHistoryRepository : CRUDRepository<EnvelopeHistory, long, EGDbContext>, IEnvelopeHistoryRepository
|
||||
{
|
||||
public class EnvelopeHistoryRepository : CRUDRepository<EnvelopeHistory, long, EGDbContext>, IEnvelopeHistoryRepository
|
||||
public EnvelopeHistoryRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeHistories)
|
||||
{
|
||||
public EnvelopeHistoryRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeHistories)
|
||||
{
|
||||
}
|
||||
|
||||
private IQueryable<EnvelopeHistory> By(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
{
|
||||
var query = _dbSet.AsQueryable();
|
||||
|
||||
if (envelopeId is not null)
|
||||
query = query.Where(eh => eh.EnvelopeId == envelopeId);
|
||||
|
||||
if (userReference is not null)
|
||||
query = query.Where(eh => eh.UserReference == userReference);
|
||||
|
||||
if (status is not null)
|
||||
query = query.Where(eh => eh.Status == status);
|
||||
|
||||
if (withSender)
|
||||
query = query.Include(eh => eh.Sender);
|
||||
|
||||
if (withReceiver)
|
||||
query = query.Include(eh => eh.Receiver);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: status).CountAsync();
|
||||
|
||||
public async Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
=> await By(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: status,
|
||||
withSender: withSender,
|
||||
withReceiver: withReceiver).ToListAsync();
|
||||
}
|
||||
|
||||
private IQueryable<EnvelopeHistory> By(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
{
|
||||
var query = _dbSet.AsQueryable();
|
||||
|
||||
if (envelopeId is not null)
|
||||
query = query.Where(eh => eh.EnvelopeId == envelopeId);
|
||||
|
||||
if (userReference is not null)
|
||||
query = query.Where(eh => eh.UserReference == userReference);
|
||||
|
||||
if (status is not null)
|
||||
query = query.Where(eh => eh.Status == status);
|
||||
|
||||
if (withSender)
|
||||
query = query.Include(eh => eh.Sender);
|
||||
|
||||
if (withReceiver)
|
||||
query = query.Include(eh => eh.Receiver);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: status).CountAsync();
|
||||
|
||||
public async Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
=> await By(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: status,
|
||||
withSender: withSender,
|
||||
withReceiver: withReceiver).ToListAsync();
|
||||
}
|
||||
@@ -1,70 +1,69 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeReceiverReadOnlyRepository : CRUDRepository<EnvelopeReceiverReadOnly, long, EGDbContext>, IEnvelopeReceiverReadOnlyRepository
|
||||
{
|
||||
public class EnvelopeReceiverReadOnlyRepository : CRUDRepository<EnvelopeReceiverReadOnly, long, EGDbContext>, IEnvelopeReceiverReadOnlyRepository
|
||||
private readonly IEnvelopeRepository _envRepo;
|
||||
|
||||
public EnvelopeReceiverReadOnlyRepository(EGDbContext dbContext, IEnvelopeRepository envelopeRepository) : base(dbContext, dbContext.EnvelopeReceiverReadOnlys)
|
||||
{
|
||||
private readonly IEnvelopeRepository _envRepo;
|
||||
_envRepo = envelopeRepository;
|
||||
}
|
||||
|
||||
public EnvelopeReceiverReadOnlyRepository(EGDbContext dbContext, IEnvelopeRepository envelopeRepository) : base(dbContext, dbContext.EnvelopeReceiverReadOnlys)
|
||||
{
|
||||
_envRepo = envelopeRepository;
|
||||
}
|
||||
protected override IQueryable<EnvelopeReceiverReadOnly> ReadOnly()
|
||||
{
|
||||
return base.ReadOnly()
|
||||
//TODO: add again when EnvelopeId data type is standardized
|
||||
//.Include(erro => erro.Envelope)
|
||||
.Include(erro => erro.Receiver);
|
||||
}
|
||||
|
||||
protected override IQueryable<EnvelopeReceiverReadOnly> ReadOnly()
|
||||
{
|
||||
return base.ReadOnly()
|
||||
//TODO: add again when EnvelopeId data type is standardized
|
||||
//.Include(erro => erro.Envelope)
|
||||
.Include(erro => erro.Receiver);
|
||||
}
|
||||
public async override Task<IEnumerable<EnvelopeReceiverReadOnly>> ReadAllAsync()
|
||||
{
|
||||
var erros = await base.ReadAllAsync();
|
||||
return await IncludeEnvelope(erros);
|
||||
}
|
||||
|
||||
public async override Task<IEnumerable<EnvelopeReceiverReadOnly>> ReadAllAsync()
|
||||
{
|
||||
var erros = await base.ReadAllAsync();
|
||||
return await IncludeEnvelope(erros);
|
||||
}
|
||||
public override async Task<EnvelopeReceiverReadOnly?> ReadByIdAsync(long id)
|
||||
{
|
||||
var erro = await _dbSet.AsNoTracking()
|
||||
.Include(erro => erro.Receiver)
|
||||
.Where(erro => erro.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
public override async Task<EnvelopeReceiverReadOnly?> ReadByIdAsync(long id)
|
||||
{
|
||||
var erro = await _dbSet.AsNoTracking()
|
||||
.Include(erro => erro.Receiver)
|
||||
.Where(erro => erro.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
return await IncludeEnvelope(erro);
|
||||
}
|
||||
|
||||
return await IncludeEnvelope(erro);
|
||||
}
|
||||
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<EnvelopeReceiverReadOnly> IncludeEnvelope(EnvelopeReceiverReadOnly erro)
|
||||
{
|
||||
erro.Envelope = await _envRepo.ReadByIdAsync((int)erro.EnvelopeId);
|
||||
return erro;
|
||||
}
|
||||
|
||||
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<EnvelopeReceiverReadOnly> IncludeEnvelope(EnvelopeReceiverReadOnly erro)
|
||||
{
|
||||
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<IEnumerable<EnvelopeReceiverReadOnly>> IncludeEnvelope(params EnvelopeReceiverReadOnly[] erros)
|
||||
{
|
||||
foreach (var erro in erros)
|
||||
erro.Envelope = await _envRepo.ReadByIdAsync((int) erro.EnvelopeId);
|
||||
|
||||
return erros;
|
||||
}
|
||||
|
||||
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<T> IncludeEnvelope<T>(T erros)
|
||||
where T : IEnumerable<EnvelopeReceiverReadOnly>
|
||||
{
|
||||
foreach (var erro in erros)
|
||||
erro.Envelope = await _envRepo.ReadByIdAsync((int)erro.EnvelopeId);
|
||||
return erro;
|
||||
}
|
||||
|
||||
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<IEnumerable<EnvelopeReceiverReadOnly>> IncludeEnvelope(params EnvelopeReceiverReadOnly[] erros)
|
||||
{
|
||||
foreach (var erro in erros)
|
||||
erro.Envelope = await _envRepo.ReadByIdAsync((int) erro.EnvelopeId);
|
||||
|
||||
return erros;
|
||||
}
|
||||
|
||||
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<T> IncludeEnvelope<T>(T erros)
|
||||
where T : IEnumerable<EnvelopeReceiverReadOnly>
|
||||
{
|
||||
foreach (var erro in erros)
|
||||
erro.Envelope = await _envRepo.ReadByIdAsync((int)erro.EnvelopeId);
|
||||
|
||||
return erros;
|
||||
}
|
||||
return erros;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,64 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeRepository : CRUDRepository<Envelope, int, EGDbContext>, IEnvelopeRepository
|
||||
{
|
||||
public class EnvelopeRepository : CRUDRepository<Envelope, int, EGDbContext>, IEnvelopeRepository
|
||||
public EnvelopeRepository(EGDbContext dbContext) : base(dbContext, dbContext.Envelopes)
|
||||
{
|
||||
public EnvelopeRepository(EGDbContext dbContext) : base(dbContext, dbContext.Envelopes)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Envelope>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false)
|
||||
{
|
||||
var query = _dbSet.AsNoTracking();
|
||||
public async Task<IEnumerable<Envelope>> ReadAllWithAsync(bool documents = false, bool history = false, bool documentReceiverElement = false)
|
||||
{
|
||||
var query = _dbSet.AsNoTracking();
|
||||
|
||||
if (documents)
|
||||
if (documentReceiverElement)
|
||||
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
|
||||
else
|
||||
query = query.Include(e => e.Documents);
|
||||
if (documents)
|
||||
if (documentReceiverElement)
|
||||
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
|
||||
else
|
||||
query = query.Include(e => e.Documents);
|
||||
|
||||
if (history)
|
||||
query = query.Include(e => e.History);
|
||||
if (history)
|
||||
query = query.Include(e => e.History);
|
||||
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Envelope?> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false)
|
||||
{
|
||||
var query = _dbSet.AsNoTracking().Where(e => e.Uuid == uuid);
|
||||
public async Task<Envelope?> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false)
|
||||
{
|
||||
var query = _dbSet.AsNoTracking().Where(e => e.Uuid == uuid);
|
||||
|
||||
if (withAll || withDocuments)
|
||||
if (withAll || withDocumentReceiverElement)
|
||||
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
|
||||
else
|
||||
query = query.Include(e => e.Documents);
|
||||
if (withAll || withDocuments)
|
||||
if (withAll || withDocumentReceiverElement)
|
||||
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
|
||||
else
|
||||
query = query.Include(e => e.Documents);
|
||||
|
||||
if (withAll || withUser)
|
||||
query = query.Include(e => e.User!);
|
||||
if (withAll || withUser)
|
||||
query = query.Include(e => e.User!);
|
||||
|
||||
if (withAll || withHistory)
|
||||
query = query.Include(e => e.History);
|
||||
if (withAll || withHistory)
|
||||
query = query.Include(e => e.History);
|
||||
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Envelope>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
|
||||
{
|
||||
var query = _dbSet.AsNoTracking().Where(e => e.UserId == userId);
|
||||
public async Task<IEnumerable<Envelope>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
|
||||
{
|
||||
var query = _dbSet.AsNoTracking().Where(e => e.UserId == userId);
|
||||
|
||||
if (min_status is not null)
|
||||
query = query.Where(e => e.Status >= min_status);
|
||||
if (min_status is not null)
|
||||
query = query.Where(e => e.Status >= min_status);
|
||||
|
||||
if (max_status is not null)
|
||||
query = query.Where(e => e.Status <= max_status);
|
||||
if (max_status is not null)
|
||||
query = query.Where(e => e.Status <= max_status);
|
||||
|
||||
foreach (var ignore_status in ignore_statuses)
|
||||
query = query.Where(e => e.Status != ignore_status);
|
||||
foreach (var ignore_status in ignore_statuses)
|
||||
query = query.Where(e => e.Status != ignore_status);
|
||||
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeTypeRepository : CRUDRepository<EnvelopeType, int, EGDbContext>, IEnvelopeTypeRepository
|
||||
{
|
||||
public class EnvelopeTypeRepository : CRUDRepository<EnvelopeType, int, EGDbContext>, IEnvelopeTypeRepository
|
||||
public EnvelopeTypeRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeTypes)
|
||||
{
|
||||
public EnvelopeTypeRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeTypes)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +1,86 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class EnvelopeReceiverRepository : CRUDRepository<EnvelopeReceiver, (int Envelope, int Receiver), EGDbContext>, IEnvelopeReceiverRepository
|
||||
{
|
||||
public class EnvelopeReceiverRepository : CRUDRepository<EnvelopeReceiver, (int Envelope, int Receiver), EGDbContext>, IEnvelopeReceiverRepository
|
||||
public EnvelopeReceiverRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeReceivers)
|
||||
{
|
||||
public EnvelopeReceiverRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeReceivers)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private IQueryable<EnvelopeReceiver> ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false, bool readOnly = true)
|
||||
{
|
||||
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
|
||||
private IQueryable<EnvelopeReceiver> ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false, bool readOnly = true)
|
||||
{
|
||||
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
|
||||
|
||||
if (uuid is not null)
|
||||
query = query.Where(er => er.Envelope != null && er.Envelope.Uuid == uuid);
|
||||
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 (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 (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;
|
||||
}
|
||||
if (withReceiver)
|
||||
query = query.Include(er => er.Receiver);
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = true)
|
||||
=> await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync();
|
||||
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = true)
|
||||
=> await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync();
|
||||
|
||||
public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = true)
|
||||
=> await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync();
|
||||
public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = true)
|
||||
=> await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync();
|
||||
|
||||
public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
|
||||
=> await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).FirstOrDefaultAsync();
|
||||
public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
|
||||
=> await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).FirstOrDefaultAsync();
|
||||
|
||||
public async Task<string?> ReadAccessCodeAsync(string uuid, string signature, bool readOnly = true)
|
||||
=> await ReadWhere(uuid: uuid, signature: signature, readOnly: readOnly)
|
||||
.Select(er => er.AccessCode)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
|
||||
|
||||
private IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId, bool readOnly = true)
|
||||
{
|
||||
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
|
||||
return query.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
|
||||
}
|
||||
|
||||
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = true)
|
||||
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = true)
|
||||
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly)
|
||||
public async Task<string?> ReadAccessCodeAsync(string uuid, string signature, bool readOnly = true)
|
||||
=> await ReadWhere(uuid: uuid, signature: signature, readOnly: readOnly)
|
||||
.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);
|
||||
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public async Task<EnvelopeReceiver?> ReadLastByReceiver(string email)
|
||||
{
|
||||
return await _dbSet.Where(er => er.Receiver!.EmailAddress == email).OrderBy(er => er.EnvelopeId).LastOrDefaultAsync();
|
||||
}
|
||||
private IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId, bool readOnly = true)
|
||||
{
|
||||
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
|
||||
return query.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
|
||||
}
|
||||
|
||||
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = true)
|
||||
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = true)
|
||||
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly)
|
||||
.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();
|
||||
}
|
||||
|
||||
public async Task<EnvelopeReceiver?> ReadLastByReceiver(string email)
|
||||
{
|
||||
return await _dbSet.Where(er => er.Receiver!.EmailAddress == email).OrderBy(er => er.EnvelopeId).LastOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,36 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class ReceiverRepository : CRUDRepository<Receiver, int, EGDbContext>, IReceiverRepository
|
||||
{
|
||||
public class ReceiverRepository : CRUDRepository<Receiver, int, EGDbContext>, IReceiverRepository
|
||||
public ReceiverRepository(EGDbContext dbContext) : base(dbContext, dbContext.Receivers)
|
||||
{
|
||||
public ReceiverRepository(EGDbContext dbContext) : base(dbContext, dbContext.Receivers)
|
||||
{
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
public async override Task<IEnumerable<Receiver>> ReadAllAsync() => await ReadBy().ToListAsync();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
public async override Task<IEnumerable<Receiver>> ReadAllAsync() => await ReadBy().ToListAsync();
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
||||
|
||||
public class UserReceiverRepository : CRUDRepository<UserReceiver, int, EGDbContext>, IUserReceiverRepository
|
||||
{
|
||||
public class UserReceiverRepository : CRUDRepository<UserReceiver, int, EGDbContext>, IUserReceiverRepository
|
||||
public UserReceiverRepository(EGDbContext dbContext) : base(dbContext, dbContext.UserReceivers)
|
||||
{
|
||||
public UserReceiverRepository(EGDbContext dbContext) : base(dbContext, dbContext.UserReceivers)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user