diff --git a/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs index e471ddf7..4aa2946c 100644 --- a/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs @@ -5,19 +5,19 @@ namespace EnvelopeGenerator.Infrastructure.Contracts { public interface IEnvelopeReceiverRepository : ICRUDRepository { - Task> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false); + Task> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = false); - Task> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true); + Task> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = false); - Task ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true); + Task ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = false); - Task ReadAccessCodeAsync(string uuid, string signature); + Task ReadAccessCodeAsync(string uuid, string signature, bool readOnly = false); Task CountAsync(string uuid, string signature); - Task ReadByIdAsync(int envelopeId, int receiverId); + Task ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = false); - Task ReadAccessCodeByIdAsync(int envelopeId, int receiverId); + Task ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = false); Task> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses); diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs index 7b72f29e..80c0970c 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs @@ -11,9 +11,9 @@ namespace EnvelopeGenerator.Infrastructure.Repositories { } - private IQueryable ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false) + private IQueryable ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false, bool readOnly = false) { - var query = _dbSet.AsNoTracking(); + var query = readOnly ? _dbSet.AsNoTracking() : _dbSet; if (uuid is not null) query = query.Where(er => er.Envelope != null && er.Envelope.Uuid == uuid); @@ -32,31 +32,34 @@ namespace EnvelopeGenerator.Infrastructure.Repositories return query; } - public async Task> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false) - => await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync(); + public async Task> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = false) + => await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync(); - public async Task> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true) - => await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync(); + public async Task> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = false) + => await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync(); - public async Task ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true) - => await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).FirstOrDefaultAsync(); + public async Task ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = false) + => await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).FirstOrDefaultAsync(); - public async Task ReadAccessCodeAsync(string uuid, string signature) - => await ReadWhere(uuid: uuid, signature: signature) + public async Task ReadAccessCodeAsync(string uuid, string signature, bool readOnly = false) + => await ReadWhere(uuid: uuid, signature: signature, readOnly: readOnly) .Select(er => er.AccessCode) .FirstOrDefaultAsync(); public async Task CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync(); - public IQueryable ReadById(int envelopeId, int receiverId) => _dbSet.AsNoTracking() - .Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId); + private IQueryable ReadById(int envelopeId, int receiverId, bool readOnly = false) + { + var query = readOnly ? _dbSet.AsNoTracking() : _dbSet; + return query.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId); + } - public async Task ReadByIdAsync(int envelopeId, int receiverId) - => await ReadById(envelopeId: envelopeId, receiverId: receiverId) + public async Task ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = false) + => await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly) .FirstOrDefaultAsync(); - public async Task ReadAccessCodeByIdAsync(int envelopeId, int receiverId) - => await ReadById(envelopeId: envelopeId, receiverId: receiverId) + public async Task ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = false) + => await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly) .Select(er => er.AccessCode) .FirstOrDefaultAsync();