public async Task <ActionResult> ConvertToOrder(CheckoutTransferObject checkoutTransferObject) { foreach (var item in checkoutTransferObject.Cart.CartItems) { var record = await _inventoryRepository.Get(item.Sku); if (record.TotalStock >= item.Quantity) { record.TotalStock -= item.Quantity; record.ReservedStock -= item.Quantity; } } await _inventoryRepository.SaveChanges(); return(Ok(true)); }
public async Task <ActionResult <OrderConfirmationTransferObject> > Checkout(CheckoutTransferObject checkoutTransferObject) { var stockSecured = await _inventoryService.Post(checkoutTransferObject); if (stockSecured) { var order = new Order { CardType = checkoutTransferObject.PaymentInfo.CardType, CardLastFourDigits = checkoutTransferObject.PaymentInfo.CardNumber.Skip(12).ToString(), City = checkoutTransferObject.Customer.Address.City, FirstLine = checkoutTransferObject.Customer.Address.FirstLine, SecondLine = checkoutTransferObject.Customer.Address.SecondLine, FirstName = checkoutTransferObject.Customer.FirstName, LastName = checkoutTransferObject.Customer.LastName, EmailAddress = checkoutTransferObject.Customer.EmailAddress, State = checkoutTransferObject.Customer.Address.State, PostalCode = checkoutTransferObject.Customer.Address.PostalCode, DeliveryCost = checkoutTransferObject.DeliveryCost, DeliveryTax = checkoutTransferObject.DeliveryTax, Total = checkoutTransferObject.Total }; _orderRepository.Create(order); await _orderRepository.SaveChanges(); _orderItemRepository.Create(checkoutTransferObject.Cart, order.Id); await _orderItemRepository.SaveChanges(); var orderConfirmation = new OrderConfirmationTransferObject { DeliveryCost = order.DeliveryCost, DeliveryTax = order.DeliveryTax, Id = order.Id, OrderDate = DateTime.Now, OrderItems = checkoutTransferObject.Cart.CartItems, Total = order.Total }; return(Ok(orderConfirmation)); } return(BadRequest()); }
public async Task <OrderConfirmationTransferObject> PostOrder(CheckoutTransferObject entity) { return(await _httpService.Post <OrderConfirmationTransferObject>($"{baseUri}api/checkoutservice/v1/Checkout", entity)); }
public async Task <ActionResult <OrderConfirmationTransferObject> > PostCheckout(CheckoutTransferObject checkout) { try { var response = await _checkoutService.PostOrder(checkout); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <bool> Post(CheckoutTransferObject entity) { return(await _httpService.Post <bool>($"{baseUri}api/inventoryservice/v1/converttoorder", entity)); }