public int?ShoppingRemoveFromCart(int id, string ShoppingCartId) { using (StoreDbEntities db = new StoreDbEntities()) { // Get the cart var cartItem = db.Cart.Single( cart => cart.CartId == ShoppingCartId && cart.RecordId == id); int?itemCount = 0; if (cartItem != null) { db.Cart.Remove(cartItem); //if (cartItem.Count > 1) //{ // cartItem.Count--; // itemCount = cartItem.Count; //} //else //{ // db.Cart.Remove(cartItem); //} //// Save changes db.SaveChanges(); } return(itemCount); } }
public void ShoppingAddMoreProductToCart(Produit produit, string ShoppingCartId, int number) { using (StoreDbEntities db = new StoreDbEntities()) { // Get the matching cart and produit instances var cartItem = db.Cart.SingleOrDefault( c => c.CartId == ShoppingCartId && c.ProduitId == produit.ProduitId); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new Cart { ProduitId = produit.ProduitId, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; db.Cart.Add(cartItem); } else { // If the item does exist in the cart, // then add one to the quantity cartItem.Count = number; } // Save changes db.SaveChanges(); } }
public void ShoppingUpdateStock(OrderDetail order) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.Produit.Find(order.ProduitId); result.Quantite -= order.Quantity; db.Entry(result).State = EntityState.Modified; db.SaveChanges(); } }
public string Add(Image image) { if (image == null) { return(null); } StoreDbEntities.Images.Add(image); StoreDbEntities.SaveChanges(); return(image.ImagePath); }
public Marque AddMarque(Marque marque) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.Marque.Add(marque); if (db.SaveChanges() > 0) { return(result); } return(null); } }
public Genre AddGenre(Genre genre) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.Genre.Add(genre); if (db.SaveChanges() > 0) { return(result); } return(null); } }
public Order AddOrder(Order order) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.Order.Add(order); if (db.SaveChanges() > 0) { return(result); } return(null); } }
public OrderDetail AddOrderDetail(OrderDetail orderDetail) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.OrderDetail.Add(orderDetail); if (db.SaveChanges() > 0) { return(result); } return(null); } }
public Produit AddProduit(Produit produit) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.Produit.Add(produit); if (db.SaveChanges() > 0) { return(result); } return(null); } }
public Cart AddCart(Cart cart) { using (StoreDbEntities db = new StoreDbEntities()) { var result = db.Cart.Add(cart); if (db.SaveChanges() > 0) { return(result); } return(null); } }
public Produit EditProduit(Produit produit) { using (StoreDbEntities db = new StoreDbEntities()) { var result = produit; db.Entry(result).State = EntityState.Modified; if (db.SaveChanges() > 0) { return(result); } } return(null); }
public Genre EditGenre(Genre genre) { using (StoreDbEntities db = new StoreDbEntities()) { var result = genre; db.Entry(result).State = EntityState.Modified; if (db.SaveChanges() > 0) { return(result); } } return(null); }
public OrderDetail EditOrderDetail(OrderDetail orderDetail) { using (StoreDbEntities db = new StoreDbEntities()) { var result = orderDetail; db.Entry(result).State = EntityState.Modified; if (db.SaveChanges() > 0) { return(result); } } return(null); }
public Cart EditCart(Cart cart) { using (StoreDbEntities db = new StoreDbEntities()) { var result = cart; db.Entry(result).State = EntityState.Modified; if (db.SaveChanges() > 0) { return(result); } } return(null); }
public Marque EditMarque(Marque marque) { using (StoreDbEntities db = new StoreDbEntities()) { var result = marque; db.Entry(result).State = EntityState.Modified; if (db.SaveChanges() > 0) { return(result); } } return(null); }
public void ShoppingMigrateCart(string userName, string ShoppingCartId) { using (StoreDbEntities db = new StoreDbEntities()) { var shoppingCart = db.Cart.Where( c => c.CartId == ShoppingCartId); foreach (Cart item in shoppingCart) { item.CartId = userName; } db.SaveChanges(); } }
public Produit RemoveProduit(int id) { using (StoreDbEntities db = new StoreDbEntities()) { if (id != 0) { var result = db.Produit.Remove(db.Produit.Find(id)); if (db.SaveChanges() > 0) { return(result); } } return(null); } }
public void ShoppingEmptyCart(string ShoppingCartId) { using (StoreDbEntities db = new StoreDbEntities()) { var cartItems = db.Cart.Where( cart => cart.CartId == ShoppingCartId); foreach (var cartItem in cartItems) { db.Cart.Remove(cartItem); } // Save changes db.SaveChanges(); } }
public Marque RemoveMarque(int id) { using (StoreDbEntities db = new StoreDbEntities()) { if (id != 0) { var result = db.Marque.Remove(db.Marque.Find(id)); if (db.SaveChanges() > 0) { return(result); } } return(null); } }
public void Create(Log obj) { obj.Date = DateTime.Today; //UNIX Time = 1300123800000; try { StoreDb.Logs.Add(obj); StoreDb.SaveChanges(); } catch (Exception) { } }
public OrderDetail RemoveOrderDetail(int id) { using (StoreDbEntities db = new StoreDbEntities()) { if (id != 0) { var result = db.OrderDetail.Remove(db.OrderDetail.Find(id)); if (db.SaveChanges() > 0) { return(result); } } return(null); } throw new NotImplementedException(); }
public int ShoppingCreateOrder(Order order, string myShoppingCartId) { using (StoreDbEntities db = new StoreDbEntities()) { decimal?orderTotal = 0; var cartItems = ShoppingGetCartItems(myShoppingCartId); // Iterate over the items in the cart, // adding the order details for each foreach (var item in cartItems) { var orderDetail = new OrderDetail { ProduitId = item.ProduitId, OrderId = order.OrderId, UnitPrice = item.Produit.Price, Quantity = item.Count }; // Set the order total of the shopping cart orderTotal += (item.Count * item.Produit.Price); db.OrderDetail.Add(orderDetail); } // Set the order's total to the orderTotal count order.Total = orderTotal; // Save the order db.SaveChanges(); // Empty the shopping cart //EmptyCart(); // Return the OrderId as the confirmation number return(order.OrderId); } }
public void Create(Product product) { StoreDb.Products.Add(product); StoreDb.SaveChanges(); }
public void Create(User user) { userDb.Users.Add(user); userDb.SaveChanges(); }