public async Task HandleAsync(CreateOrderCommand command, ICorrelationContext context) { var order = new D.MoveOn.Order.Domain.Order(command.Id, command.Name, command.ProductId); await _ordersRepository.AddAsync(order); await _busPublisher.PublishAsync <ResultProcess>(new ResultProcess(Guid.NewGuid(), context.UserId, "Duong", "test"), context); }
public async Task HandleAsync(CreateOrder command, ICorrelationContext context) { await _ordersRepository.AddAsync(new DomainEntities.Order( command.Id, command.CustomerId, MapToOraderItems(command.OrderItems)) ); }
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); }
public async Task HandleAsync(CreateOrderCommand command) { // TODO: zmienić logikę, bo teraz klient może mimeć tylko jedno aktywne zamówineie. Zrobi unikatowe id koszyka. // TODO: żeby złożyć zamównienie to klient musi uzupełnić swoje dane. if (await _ordersRepository.HasPendingOrderAsync(command.CustomerId)) { throw new MyShopException("customer_has_pending_order", $"Customer with id: '{command.CustomerId}' has already a pending order."); } var cart = await _cartsRepository.GetAsync(command.CustomerId); var order = new Order(command.Id, command.CustomerId, cart); await _ordersRepository.AddAsync(order); cart.Clear(); }
public async Task <IActionResult> AddOrderAsync([FromBody] Order order) { try { order.OrderStatuses.Clear(); order.OrderStatuses.Add(new OrderStatus { Status = OrderStatuses.Placed, StatusChangeTime = DateTime.Now }); order.LatestOrderStatus = OrderStatuses.Placed; order.CreationDate = DateTime.Now; var addedOrder = await ordersRepository.AddAsync(order); return(Ok()); } catch { return(BadRequest()); } }
public async Task <Order> CreateOrderAsync(User user, IList <ProductOrder> productOrders, Shipment shipment, Payment payment, OrderDiscount orderDiscount, string comment, Address address) { if (!productOrders.Any()) { throw new ArgumentException("Empty product orders"); } var productNames = string.Join(", ", productOrders.Select(s => s.Product).Select(s => s.Name)); logger.LogInformation($"Creating new order for products: {productNames}"); var basePrice = productOrders.Sum(s => (s.CurrentProductPrice + s.CharmsPrice) * s.Amount); if (basePrice <= 0) { throw new Exception("Order base price is below 0."); } var finalPrice = productOrders.Sum(s => s.FinalPrice * s.Amount); if (orderDiscount != null) { var discountValue = (orderDiscount.PercentValue / 100M) * finalPrice; finalPrice -= discountValue; } var order = new Order(user, productOrders, orderDiscount, shipment, payment, basePrice, finalPrice, comment, address); logger.LogInformation($"Trying add order {order.Id}, with base price {basePrice}..."); await ordersRepository.AddAsync(order); await ordersRepository.SaveChangesAsync(); logger.LogInformation($"Order id: {order.Id} added successfully !!!"); return(order); }