public static Response DeleteCart(int ProductID, int UserID) { Cart cart = CartRepositories.DeleteCart(ProductID, UserID); if (cart != null) { return(new Response(true)); } return(new Response(false, "Cart cant be found")); }
public static Response doCheckout(List <Cart> carts, int UserID, int PaymentTypeID, DateTime date) { Header_Transaction headerTran = TransactionsFactories.InsertHeaderTransaction(UserID, PaymentTypeID, date); TransactionRepositories.InsertHeaderTransaction(headerTran); Detail_Transaction detailTran = new Detail_Transaction(); for (int i = 0; i < carts.Count; i++) { detailTran = TransactionsFactories.InsertDetailTransaction(headerTran.ID, carts[i].ProductID, carts[i].Quantity); TransactionRepositories.InsertDetailTransaction(detailTran); CartRepositories.DeleteCart(carts[i].ProductID, UserID); } return(new Response(true)); }
public static Response DeleteProduct(int ProductID) { Cart cart = CartRepositories.GetCartByProduct(ProductID); Detail_Transaction detailTran = TransactionRepositories.GetDetailTransactionByProductID(ProductID); if (cart != null || detailTran != null) { return(new Response(false, "Cant delete this product because its referenced in another table in database")); } Product pro = ProductRepositories.GetProduct(ProductID); if (pro != null) { ProductRepositories.DeleteProduct(ProductID); return(new Response(true)); } return(new Response(false, "cant find the product")); }
public static Response UpdateCart(int ProductID, int UserID, int Quantity) { Product pro = ProductRepositories.GetProduct(ProductID); if (Quantity > pro.Stock) { return(new Response(false, "Quantity must be less than or equals to current stock ")); } List <Cart> CartList = CartRepositories.GetCartbyProduct(ProductID); Cart cart = CartRepositories.GetCart(ProductID, UserID); if (Quantity == 0) { CartRepositories.DeleteCart(ProductID, UserID); return(new Response(true)); } if (CartList.Any()) { int total = TotalInCart(CartList); int stock = pro.Stock - total + cart.Quantity; if (Quantity > stock) { return(new Response(false, "Quantity must be " + stock.ToString() + "or below")); } else { CartRepositories.UpdateCart(cart, Quantity); return(new Response(true)); } } CartRepositories.UpdateCart(cart, Quantity); return(new Response(true)); }
public static Cart GetCart(int ProductID, int UserID) { return(CartRepositories.GetCart(ProductID, UserID)); }
public static List <Cart> GetCartbyUser(int UserID) { return(CartRepositories.GetCartbyUser(UserID)); }
public static Response InsertCart(int UserID, int ProductID, int Quantity) { Product pro = ProductRepositories.GetProduct(ProductID); if (Quantity > pro.Stock) { return(new Response(false, "Quantity must be less than or equals to current stock ")); } int total = 0; List <Cart> CartList = CartRepositories.GetCartbyProduct(ProductID); if (CartList.Any()) { total = TotalInCart(CartList); int stock = pro.Stock - total; if (Quantity > stock) { if (stock < 1) { return(new Response(false, "Cant add to cart because out of stock.")); } else { return(new Response(false, "Quantity must be " + stock.ToString() + " or below")); } } } Cart CheckCartExists = CartRepositories.GetCart(ProductID, UserID); if (CheckCartExists != null) { int stock = pro.Stock - total; if (Quantity > stock) { if (stock < 1) { return(new Response(false, "Cant add to cart because out of stock.")); } else { return(new Response(false, "Quantity must be " + stock.ToString() + " or below")); } } else { CartRepositories.UpdateCart(CheckCartExists, Quantity + CheckCartExists.Quantity); return(new Response(true)); } } Cart cart = CartFactories.InsertCart(UserID, ProductID, Quantity); CartRepositories.InsertCart(cart); return(new Response(true)); }