public static Response DoAddToCart(int userId, int productId, int qty) { int n = 0; bool isNumeric = int.TryParse(qty.ToString(), out n); Product p = ProductHandler.GetProduct(productId); if (isNumeric == false) { return(new Response(false, "must be numeric")); } else if (qty <= 0) { return(new Response(false, "must be more than 0")); } else if (qty > p.Stock) { return(new Response(false, "must be less than or equals to current stock")); } else { Response respond = AddToCartHandler.DoAddToCart(userId, productId, qty, p.Stock); return(respond); } }
public static Response DoAddCart(String UserID, String ProductID, int qty) { if (qty <= 0) { return(new Response(false, "Quantity Must Be More Than 0")); } Response response = AddToCartHandler.DoAddCart(UserID, ProductID, qty); return(response); }
public static string UpdateCartController(Cart cart, int productId) { int equal = AddToCartHandler.returnStock(productId); if (cart.Quantity < 0) { return("Input Invalid!"); } else if (equal < cart.Quantity) { return("There's not enough stock for that product"); } CartHandler.UpdateCartHandler(cart); return("Success"); }
public static Boolean AddToCartValidation(User user, int stock, int productId, out string errorMessage) { Cart cart = AddToCartHandler.returnGetCart(user.Id, productId); int equal = AddToCartHandler.returnStock(productId); int productStock = equal - stock; int cartQuantity = 0; if (cart == null) { cartQuantity = 0; } else { cartQuantity = cart.Quantity; } int stockQuantity = stock + cartQuantity; errorMessage = ""; if (stock <= 0) { errorMessage = "Stock input must be more than 0"; return(false); } else if (stock > equal) { errorMessage = "Stock input is too much"; return(false); } else if (stockQuantity > equal) { errorMessage = "Input must be less than " + (equal - cart.Quantity); return(false); } else if (AddToCartHandler.returnGetCart(user.Id, productId) == null) { AddToCartHandler.InsertNewCartHandler(user.Id, productId, stock); return(true); } else { AddToCartHandler.UpdateQuantityCart(user.Id, productId, stock); return(true); } }
public static MsProductType GetProductType(String ID) { return(AddToCartHandler.GetProductType(ID)); }
public static MsProduct FetchDataByID(String ID) { return(AddToCartHandler.FetchDataByID(ID)); }