Ejemplo n.º 1
0
 public void DeleteAllProduts()
 {
     foreach (var p in GetAllProducts())
     {
         _ctx.Products.Remove(p);
     }
     _ctx.SaveChanges();
 }
Ejemplo n.º 2
0
        public void AddToCart(Product product, int amount)
        {
            var shopingCartItem = _ctx.ShopingCartItems.SingleOrDefault(
                s => s.Product.ProductId == product.ProductId && s.ShopingCartId == ShopingCartId);

            if (shopingCartItem == null)
            {
                shopingCartItem = new ShoppingCartItem
                {
                    ShopingCartId = ShopingCartId,
                    Product       = product,
                    Amount        = amount
                };
                _ctx.ShopingCartItems.Add(shopingCartItem);
            }
            else
            {
                shopingCartItem.Amount++;
            }
            _ctx.SaveChanges();
        }
Ejemplo n.º 3
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;
            _ctx.Orders.Add(order);
            var shoppingCartItems = _shoppingCart.ShoppingCartItems;

            foreach (var item in shoppingCartItems)
            {
                var orderDetail = new OrderDetail()
                {
                    Amount    = item.Amount,
                    ProductId = item.Product.ProductId,
                    OrderId   = order.OrderId,
                    Price     = item.Product.Price
                };
                _ctx.OrderDetails.Add(orderDetail);
            }
            _ctx.SaveChanges();
        }