protected void TextBox1_TextChanged(object sender, EventArgs e) { // selecttotal quantity of product : HttpCookie cookie = Request.Cookies["MyCookie"]; if (cookie != null) { int user_id = int.Parse(cookie["userId"].ToString()); string product_id_toEdit = ((TextBox)sender).CssClass; //string user_id = "1";// can get it by session for ex. //cart_id = user_id. DataTable dt = Carts.GetTotalProductQuantity(int.Parse(product_id_toEdit)); if (int.Parse(dt.Rows[0][0].ToString()) > int.Parse(((TextBox)sender).Text)) { Cart_Attripute cart = new Cart_Attripute() { User_Id = user_id, Product_Id = int.Parse(product_id_toEdit), Quantity = int.Parse(((TextBox)sender).Text) }; Carts.Update(cart); } else { } Response.Redirect("Cart.aspx"); } else { Response.Redirect("LogIn.aspx"); } }
////////////////////i edit this/////////////////////// public static int Update(Cart_Attripute cart) { string state = $"Update Cart set Quantity = {cart.Quantity} where User_Id = {cart.User_Id} and P_Id = {cart.Product_Id}"; return(Connection.ExecuteNonQuery(state)); }
public static int Insert(Cart_Attripute cart) { string state = $"insert into Cart (User_Id, Quantity, P_Id) values ({cart.User_Id}, {cart.Quantity}, {cart.Product_Id})"; return(Connection.ExecuteNonQuery(state)); }