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 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)); }