public static Response UpdateCart(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 > p.Stock) { return(new Response(false, "must be less than or equals to current stock")); } else if (qty < 0) { return(new Response(false, "input field cannot be inputted below 0")); } else { CartHandler.UpdateCart(userId, productId, qty); return(new Response(true)); } }
public static Response UpdateCart(int userId, int productId, string quantity) { if (quantity == "" || quantity.All(char.IsDigit) != true) { return(new Response(false, "Quantity cannot be empty or non numeric")); } int _quantity = Int32.Parse(quantity); if (CartHandler.UpdateCart(userId, productId, _quantity)) { return(new Response(true, "Cart has been updated")); } return(new Response(false, "Quantity invalid")); }
public void UpdateCart(string productID, object userID, TextBox txtQuantity, Label lblErrorSubmit, Label Stock) { int ProductID = Int32.Parse(productID); int UserID = Int32.Parse(userID.ToString()); Product currentProduct = new ProductHandler().GetProductByID(ProductID); Cart currentCart = new CartHandler().GetCartByTwoId(UserID, ProductID); int currentListTotal = new CartHandler().CountListByProductId(ProductID) + currentProduct.Stock; if (Int32.Parse(txtQuantity.Text) > currentListTotal || Int32.Parse(txtQuantity.Text) == 0 || Int32.Parse(txtQuantity.Text) == currentCart.Quantity) { txtQuantity.Text = ""; lblErrorSubmit.Text = "Please input a valid quantity"; lblErrorSubmit.ForeColor = System.Drawing.Color.Red; lblErrorSubmit.Visible = true; } else if (txtQuantity != null) { int Quantity = Int32.Parse(txtQuantity.Text); if (Int32.Parse(txtQuantity.Text) > currentCart.Quantity) { int QuantityInput = Int32.Parse(txtQuantity.Text) - currentCart.Quantity; new ProductHandler().SubstractProductStockById(ProductID, QuantityInput); } else { int QuantityInput = currentCart.Quantity - Int32.Parse(txtQuantity.Text); new ProductHandler().AddProductStockById(ProductID, QuantityInput); } CartHandler.UpdateCart(UserID, ProductID, Quantity); txtQuantity.Text = ""; lblErrorSubmit.ForeColor = System.Drawing.Color.Black; lblErrorSubmit.Text = "Successfully updated cart."; lblErrorSubmit.Visible = true; Product NewProduct = new ProductHandler().GetProductByID(ProductID); Stock.Text = NewProduct.Stock.ToString(); HttpContext.Current.Response.Redirect("ViewCart.aspx"); } }
public static Response UpdateCart(int ProductID, int UserID, string QuantityTxt) { if (QuantityTxt == "") { return(new Response(false, "Quantity must be filled")); } int Quantity; if (!int.TryParse(QuantityTxt, out Quantity)) { return(new Response(false, "Quantity must be numeric")); } Quantity = int.Parse(QuantityTxt); if (Quantity < 0) { return(new Response(false, "Quantity must be 0 or more than 0")); } Response response = CartHandler.UpdateCart(ProductID, UserID, Quantity); return(response); }