Esempio n. 1
0
        public async Task <bool> Handle(CreateOrderCommand notification, CancellationToken cancellationToken)
        {
            await _unitOfWork.BeginTransactionAsync();

            var orderItems = notification.OrderItems.Select(x => OrderItem.CreateOrderItem(x.ProductId, x.Quantity));

            var order = Order.CreateOrder(notification.CustomerId, notification.Description, orderItems);

            _orderRepository.Add(order);

            await _unitOfWork.SaveEntitiesAsync();

            var @event = new OrderCreatedIntegrationEvent(order, true);

            await _integrationEventService.SaveEventAsync(@event);

            await _unitOfWork.SaveChangesAsync();

            await _unitOfWork.CommitAsync();

            await _integrationEventService.PublishAsync(@event);

            return(true);
        }