public static void DeleteProduct(String UserID, String ProductID) { MsCart cart = SearchCart(UserID, ProductID); db.MsCarts.Remove(cart); db.SaveChanges(); }
public static Response DoAddCart(String UserID, String ProductID, int qty) { MsProduct product = Repository.RepositoryMsProduct.SearchProductByID(ProductID); int servedqty = Repository.RepositoryCart.GetServedQty(ProductID); MsCart cart = Repository.RepositoryCart.SearchCart(UserID, ProductID); if (qty > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } if ((qty + servedqty) > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } if (cart == null) { Repository.RepositoryCart.InsertCart(UserID, ProductID, qty); } else { Repository.RepositoryCart.AppendCart(UserID, ProductID, qty); } return(new Response(true)); }
public static void AppendCart(String UserID, String ProductID, int qty) { MsCart cart = SearchCart(UserID, ProductID); cart.Quantity = cart.Quantity + qty; db.SaveChanges(); }
public static void UpdateCart(String ProductID, String UserID, int Quantity) { MsCart cart = SearchCart(UserID, ProductID); cart.Quantity = Quantity; db.SaveChanges(); }
public static MsCart InitCart(String UserID, String ProductID, int qty) { MsCart newcart = new MsCart(); newcart.UserID = UserID; newcart.ProductID = ProductID; newcart.Quantity = qty; return(newcart); }
public static int GetServedQty(String ProductID) { MsCart temp = (from x in db.MsCarts where x.ProductID == ProductID select x).FirstOrDefault(); if (temp != null) { return((from x in db.MsCarts where x.ProductID == ProductID select x.Quantity).Sum()); } else { return(0); } }
public static void DoCheckout(String UserID, String PaymentID) { int numbercart = Repository.RepositoryCart.CountCart(UserID); int ID = Repository.RepositoryHeaderTransaction.CountHeeader(); Repository.RepositoryHeaderTransaction.InsertHeader(ID, UserID, PaymentID); for (int i = 0; i < numbercart; i++) { MsCart cart = Repository.RepositoryCart.SearchUserCart(UserID); String TransactionID = "TR" + ID; String ProductID = cart.ProductID; int Quantity = cart.Quantity; Repository.RepositoryDetailTransaction.insertDetail(TransactionID, ProductID, Quantity); Repository.RepositoryCart.DeleteProduct(UserID, ProductID); Repository.RepositoryMsProduct.UpdateStockProduct(ProductID, cart.Quantity); } }
public static Response UpdateCart(String UserID, String ProductID, int Qty) { MsProduct product = Repository.RepositoryMsProduct.SearchProductByID(ProductID); int servedqty = Repository.RepositoryCart.GetServedQty(ProductID); MsCart cart = Repository.RepositoryCart.SearchCart(UserID, ProductID); if (Qty == cart.Quantity) { return(new Response(true)); } if (Qty > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } if ((Qty + servedqty) > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } RepositoryCart.UpdateCart(ProductID, UserID, Qty); return(new Response(true)); }