Ejemplo n.º 1
0
        public void CreateOrder(Order order)
        {
            order.OrderDate = DateTime.Now;

            var shoppingCartItems = _shoppingcart.shoppingCartItems;

            order.OrderTotal   = _shoppingcart.shoppingCartTotal();
            order.OrderDetails = new List <OrderDetail>();

            foreach (var shoppingcartitem in shoppingCartItems)
            {
                var orderdetails = new OrderDetail
                {
                    OrderId = order.OrderId,
                    CakeId  = shoppingcartitem.cake.CakeId,
                    Amount  = shoppingcartitem.Amount,
                    Price   = shoppingcartitem.cake.Price,
                };

                order.OrderDetails.Add(orderdetails);
                _cakesdbcontext.OrderDetails.Add(orderdetails);
            }
            _cakesdbcontext.Orders.Add(order);
            _cakesdbcontext.SaveChanges();
        }
Ejemplo n.º 2
0
        public void AddtoCart(Cake cake, int amount)
        {
            var shoppingCartItem = _cakedbcontext.ShoppingCartItems.SingleOrDefault(
                s => s.cake.CakeId == cake.CakeId && s.ShoppingCartId == ShoppingCartId
                );

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    cake           = cake,
                    Amount         = amount
                };
            }
            _cakedbcontext.ShoppingCartItems.Add(shoppingCartItem);
            _cakedbcontext.SaveChanges();
        }