diff --git a/Sheaft.Mediatr/DeliveryBatch/Commands/GenerateDeliveryBatchFormsCommand.cs b/Sheaft.Mediatr/DeliveryBatch/Commands/GenerateDeliveryBatchFormsCommand.cs index eac1fdf72..ecb113b2b 100644 --- a/Sheaft.Mediatr/DeliveryBatch/Commands/GenerateDeliveryBatchFormsCommand.cs +++ b/Sheaft.Mediatr/DeliveryBatch/Commands/GenerateDeliveryBatchFormsCommand.cs @@ -46,7 +46,9 @@ public GenerateDeliveryBatchFormsCommandHandler( public async Task Handle(GenerateDeliveryBatchFormsCommand request, CancellationToken token) { - var deliveryBatch = await _context.DeliveryBatches.SingleAsync(d => d.Id == request.DeliveryBatchId, token); + var deliveryBatch = await _context.DeliveryBatches.SingleOrDefaultAsync(d => d.Id == request.DeliveryBatchId, token); + if (deliveryBatch == null) + return Result.Failure($"DeliveryBatch {request.DeliveryBatchId} was not found."); var outputDocument = new PdfDocument(); Result blobResult = null; diff --git a/Sheaft.Mediatr/User/Commands/RemoveUserDataCommand.cs b/Sheaft.Mediatr/User/Commands/RemoveUserDataCommand.cs index ccf08bbc3..cc8844c0a 100644 --- a/Sheaft.Mediatr/User/Commands/RemoveUserDataCommand.cs +++ b/Sheaft.Mediatr/User/Commands/RemoveUserDataCommand.cs @@ -46,7 +46,7 @@ public RemoveUserDataCommandHandler( public async Task> Handle(RemoveUserDataCommand request, CancellationToken token) { - var entity = await _context.Users.FirstOrDefaultAsync(c => c.Id == request.UserId, token); + var entity = await _context.Users.IgnoreQueryFilters().SingleOrDefaultAsync(c => c.Id == request.UserId, token); if (entity == null) return Failure("L'utilisateur est introuvable.");