- Bump `UserManager` package to version `1.1.1` in `EnvelopeGenerator.Application.csproj` and `EnvelopeGenerator.Infrastructure.csproj`. - Add reference to `DigitalData.UserManager.Domain` version `3.2.1.0` and `System.ComponentModel.Annotations` version `4.7.0` in `EnvelopeGenerator.CommonServices.vbproj`. - Add reference to `System.Drawing.Common` version `4.7.3` in `EnvelopeGenerator.CommonServices.vbproj`. - Update `UserManager.Domain` package to version `3.2.1` in `EnvelopeGenerator.Domain.csproj`. - Remove unused properties from `EGUser` class in `EGUser.cs`. - Mark `EnvelopeReceiverRepository` as obsolete, suggesting to use `Repository` instead. - Update `packages.config` to include new package versions.
120 lines
5.8 KiB
C#
120 lines
5.8 KiB
C#
using DigitalData.Core.Infrastructure;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.Application.Contracts.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using EnvelopeGenerator.Application.Exceptions;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure.Repositories;
|
|
|
|
[Obsolete("Use Repository")]
|
|
public class EnvelopeReceiverRepository : CRUDRepository<EnvelopeReceiver, (int Envelope, int Receiver), EGDbContext>, IEnvelopeReceiverRepository
|
|
{
|
|
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;
|
|
|
|
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, 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<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
|
|
{
|
|
var query = ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly);
|
|
|
|
return await query.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 withEnvelope = true, bool withReceiver = true, bool readOnly = true)
|
|
{
|
|
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
|
|
|
|
if (withEnvelope)
|
|
query = query
|
|
.Include(er => er.Envelope).ThenInclude(e => e!.Documents!).ThenInclude(d => d.Elements!.Where(e => e.Receiver!.Id == receiverId))
|
|
.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.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?> ReadLastByReceiverAsync(string? email = null, int? id = null, string? signature = null)
|
|
{
|
|
var parameters = new[] { email, id?.ToString(), signature }.Count(p => p != null);
|
|
|
|
if (parameters == 0)
|
|
throw new BadRequestException("You must provide either 'email', 'id', or 'signature' for the query.");
|
|
if (parameters > 1)
|
|
throw new BadRequestException("Please provide only one parameter: either 'email', 'id', or 'signature'.");
|
|
|
|
var query = _dbSet.AsNoTracking();
|
|
|
|
if(email is not null)
|
|
query = query.Where(er => er.Receiver!.EmailAddress == email);
|
|
|
|
if (id is not null)
|
|
query = query.Where(er => er.Receiver!.Id == id);
|
|
|
|
if (signature is not null)
|
|
query = query.Where(er => er.Receiver!.Signature == signature);
|
|
|
|
return await query.OrderBy(er => er.EnvelopeId).LastOrDefaultAsync();
|
|
}
|
|
} |