public void AddToCart(Product Product)
        {
            var shoppingCartItem = _eSaleDbContext.ShoppingCartItems.SingleOrDefault(
                s => s.Product.ProductId == Product.ProductId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Product        = Product
                };
                _eSaleDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                //
            }

            _eSaleDbContext.SaveChanges();
        }
Ejemplo n.º 2
0
        public void CreateOrder(Order order)
        {
            order.OrderDate  = DateTime.Now;
            order.OrderTotal = _shoppingCart.GetShoppingCartTotal();
            _context.Add(order);
            _context.SaveChanges();

            var shoppingCartItems = _shoppingCart.GetShoppingCartItems();

            foreach (var shoppingCartItem in shoppingCartItems)
            {
                var OrderItem = new OrderItem
                {
                    Price     = shoppingCartItem.Product.Price,
                    ProductId = shoppingCartItem.Product.ProductId,
                    OrderId   = order.OrderId
                };

                _context.OrderItem.Add(OrderItem);
            }

            _context.SaveChanges();
        }