コード例 #1
0
        public async Task <ActionResult> EmptyShoppingCart(string id)
        {
            await _services.EmptyCart(id);

            var shoppingCart = await _services.GetShoppingCartById(id);

            if (!shoppingCart.Any())
            {
                return(Ok());
            }

            return(NotFound());
        }
コード例 #2
0
        public async Task <int> PostOrder(int customerId, string cartId, int shippingId, int taxId)
        {
            var order = new Orders
            {
                TotalAmount = await _shoppingCartService.GetCartTotalAmount(cartId),
                Status      = 0,
                ShippingId  = shippingId,
                TaxId       = taxId,
                CustomerId  = customerId,
                CreatedOn   = DateTime.Now
            };

            await _context.Orders.AddAsync(order);

            await _context.SaveChangesAsync();

            // Line items
            var cartItems = await _shoppingCartService.GetShoppingCartById(cartId);

            foreach (var cartItem in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    OrderId     = order.OrderId,
                    ItemId      = cartItem.ItemId,
                    ProductId   = cartItem.ProductId,
                    Attributes  = cartItem.Attributes,
                    Quantity    = cartItem.Quantity,
                    ProductName = cartItem.Name,
                    UnitCost    = cartItem.Price
                };
                await _context.OrderDetail.AddAsync(orderDetail);
            }
            await _context.SaveChangesAsync();

            //Clear the cart
            await _shoppingCartService.EmptyCart(cartId);

            return(order.OrderId);
        }