public async Task HandleAsync(CompleteDeliveryCommand command, CancellationToken cancellationToken) { try { using (var session = documentStore.OpenAsyncSession()) { var deliveryDocument = await session.LoadDeliveryAsync(command.TransactionId, cancellationToken).ConfigureAwait(false); requestValidator.ValidateAndThrow(command, deliveryDocument); if (deliveryDocument.Status == DeliveryStatus.Finished) { return; } deliveryDocument.Status = DeliveryStatus.Finished; await session.StoreAsync(deliveryDocument, command.DocumentVersion, deliveryDocument.Id, cancellationToken).ConfigureAwait(false); await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } } catch (ConcurrencyException ce) { throw new ConcurrentUpdateException("The entity requested for modification has been modified by another client since it was loaded.", ce); } }
public async Task <IActionResult> CompleteDelivery(string transactionId, [FromHeader(Name = CustomHttpHeaderKeys.EntityVersion)] string documentVersion, CancellationToken cancellationToken) { var command = new CompleteDeliveryCommand(transactionId, documentVersion); await completeDeliveryCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false); return(NoContent()); }
public async Task <Delivery> CompleteDelivery( [GraphQLType(typeof(CompleteDeliveryInputType))][GraphQLName("input")] CompleteDeliveryCommand input, [Service] ISheaftMediatr mediatr, DeliveriesByIdBatchDataLoader dataLoader, CancellationToken token) { await ExecuteAsync(mediatr, input, token); return(await dataLoader.LoadAsync(input.DeliveryId, token)); }
public CompleteDeliveryCommandHandlerTest() { loadingPlaceRepo = new Mock <ILoadingPlaceRepo>(); bus = new Mock <IBus>(); command = new CompleteDeliveryCommand(id); commandHandler = new CompleteDeliveryCommandHandler(loadingPlaceRepo.Object, bus.Object); packsToDelivery = new List <PackToDelivery> { new PackToDelivery(), new PackToDelivery() }; loadingPlace = new LoadingPlace { PacksToDelivery = packsToDelivery }; }