public virtual async Task <Response> TransferOrderToOmnium(OmniumOrder omniumOrder) { _logger.Information($"Sending order with id {omniumOrder.OrderNumber} to Omnium"); var orderResponse = await _orderClient.AddOrderAsync(omniumOrder); if (orderResponse.IsSuccess()) { _logger.Information($"Order with id {omniumOrder.OrderNumber} successfully sent to Omnium"); } else { _logger.Warning($"Failed sending order {omniumOrder.OrderNumber} to Omnium, status {orderResponse.HttpStatusCode}"); var exception = orderResponse.OriginalException; if (exception != null) { _logger.Error(exception.Message, exception); } } return(orderResponse); }
public async Task <IActionResult> CheckoutAsync([FromBody] CheckoutRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } // Usually, you would get userid from an access token, for example. This is hardcoded for simplicity. var userID = 1; var cart = await mCartClient.GetCartByUserIDAsync(userID); if (!cart.CartItems.Any()) { return(BadRequest()); } var getproductTasks = cart.CartItems.Select(ci => mProductClient.GetProductAsync(ci.ProductID)).ToList(); var orderItems = new List <XAddOrderItemRequestItems>(); for (int i = 0; i < getproductTasks.Count; i++) { var product = await getproductTasks[i]; orderItems.Add(new XAddOrderItemRequestItems { ProductID = product.ID, Quantity = cart.CartItems[i].Quantity, Price = product.Price }); } var bAddOrderSuccess = await mOrderClient.AddOrderAsync(new XAddOrderRequest { UserID = userID, Address = request.Address, DeliveryMethod = request.DeliveryMethod.Value, OrderItems = orderItems }); if (!bAddOrderSuccess) { return(new ObjectResult(null) { StatusCode = (int)HttpStatusCode.InternalServerError }); } var bUpdateCartStatusSuccess = await mCartClient.UpdateCartStatus(userID, new XUpdateCartStatusRequest { Status = EXCartStatus.Ordered }); if (!bUpdateCartStatusSuccess) { return(new ObjectResult(null) { StatusCode = (int)HttpStatusCode.InternalServerError }); } return(Ok()); }