コード例 #1
0
        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));
        }
コード例 #2
0
        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());
        }
コード例 #3
0
 public async Task <OrderConfirmationTransferObject> PostOrder(CheckoutTransferObject entity)
 {
     return(await _httpService.Post <OrderConfirmationTransferObject>($"{baseUri}api/checkoutservice/v1/Checkout", entity));
 }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
 public async Task <bool> Post(CheckoutTransferObject entity)
 {
     return(await _httpService.Post <bool>($"{baseUri}api/inventoryservice/v1/converttoorder", entity));
 }