Пример #1
0
        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);
            }
        }
Пример #2
0
        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());
        }
Пример #3
0
        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));
        }
Пример #4
0
 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
     };
 }