Beispiel #1
0
        public void CreateOrder(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }
            order.OrderPlaced = DateTime.Now;


            var cartItems = cart.ShoppingCartItems;

            order.OrderTotal = cart.GetShoppingCartTotal();

            order.OrderDetails = new List <OrderDetail>();
            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    Amount = item.Amount,
                    PieId  = item.Pie.PieId,
                    Price  = item.Pie.Price
                };
                order.OrderDetails.Add(orderDetail);
            }
            dbContext.Orders.Add(order);
            dbContext.SaveChanges();
        }
Beispiel #2
0
        public void AddToCart(Pie pie, int amount)
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };

                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            _appDbContext.SaveChanges();
        }