public void DeleteAllProduts() { foreach (var p in GetAllProducts()) { _ctx.Products.Remove(p); } _ctx.SaveChanges(); }
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(); }
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(); }