public async Task HandleAsync(CreateOrder command, ICorrelationContext context)
        {
            if (await _ordersRepository.HasPendingOrder(command.CustomerId))
            {
                throw new DShopException("customer_has_pending_order",
                                         $"Customer with id: '{command.CustomerId}' has already a pending order.");
            }

            var cart = await _customersService.GetCartAsync(command.CustomerId);

            var items = cart.Items.Select(i => new OrderItem(i.ProductId,
                                                             i.ProductName, i.Quantity, i.UnitPrice)).ToList();
            var order = new Order(command.Id, command.CustomerId, items, "USD");
            await _ordersRepository.AddAsync(order);

            await _busPublisher.PublishAsync(new OrderCreated(command.Id, command.CustomerId,
                                                              items.ToDictionary(i => i.Id, i => i.Quantity)), context);
        }
Exemple #2
0
        public async Task <IActionResult> GetAsync()
        {
            var result = Single(await _customersService.GetCartAsync(UserId));

            return(result);
        }
 public async Task <IActionResult> Get()
 => Single(await _customersService.GetCartAsync(UserId));