protected override async Task Handle(ShipOrderCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderRepository.GetByIdAsync(request.OrderId);

            if (order == null)
            {
                throw new RecordNotFoundException(request.OrderId, nameof(Order));
            }

            order.Ship();

            var orderShippedIntegrationEvent = new OrderShippedIntegrationEvent(
                order.Address.City,
                order.Address.AddressLine1,
                order.Address.AddressLine2,
                order.Address.ZipCode,
                order.Client.FirstName,
                order.Client.LastName,
                order.Client.EmailAddress,
                order.Client.PhoneNumber,
                order.Items.Select(oi =>
                                   // ReSharper disable once PossibleInvalidOperationException Aggregate invariant ensures that all prices are set.
                                   new ValidatedOrderItemInfo(oi.ProductId, oi.Quantity, oi.UnitPrice.Value))
                .ToList(),
                order.Id
                );

            await _mediator.Publish(orderShippedIntegrationEvent, cancellationToken);

            await _orderRepository.UnitOfWork.SaveEntitiesAsync();
        }
Exemplo n.º 2
0
        public async Task Handle(OrderShippedDomainEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation(" [x] OrderShippedDomainEventHandler: Handling domain event...");

            var integrationEvent = new OrderShippedIntegrationEvent(orderId: notification.OrderId);

            _logger.LogInformation(" [x] OrderShippedDomainEventHandler: Publishing OrderShippedIntegrationEvent integration event...");
            await _orderingIntegrationEventService.PublishEvent(integrationEvent);
        }