public async Task <IActionResult> CancelReservation(string transactionId, CancellationToken cancellationToken) { var command = new CancelReservationsCommand(transactionId); await cancelReservationsCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false); return(NoContent()); }
public async Task HandleAsync(CancelReservationsCommand command, CancellationToken cancellationToken) { using (var context = dbContextFactory.CreateDbContext()) { requestValidator.ValidateAndThrow(command); var productReservations = await context .ProductReservations .Where(evt => evt.TransactionId == command.TransactionId) .ToListAsync(cancellationToken) .ConfigureAwait(false); if (productReservations.Count == 0) { return; } context.ProductReservations.RemoveRange(productReservations); await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } }