public bool delete(ItemIngredientRequirement itm) { bool result = false; con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString); try { cmd = new SqlCommand( "DELETE FROM ingredient_list WHERE menu_item_id = @menu_id AND ingredient_id=@ing_id", con); cmd.Parameters.AddWithValue("@menu_id", itm.menuItemId); cmd.Parameters.AddWithValue("@ing_id", itm.ingredientId); con.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { result = true; } else { result = false; } } catch (Exception e) { MessageBox.Show(e.ToString(), "Error"); } finally { con.Close(); } return(result); }
public bool insert(ItemIngredientRequirement itm) { bool result = false; con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString); try { cmd = new SqlCommand( "INSERT INTO ingredient_list (menu_item_id, ingredient_id, quantity) VALUES(@menu_id,@ing_id,@quantity)", con); cmd.Parameters.AddWithValue("@menu_id", itm.menuItemId); cmd.Parameters.AddWithValue("@ing_id", itm.ingredientId); cmd.Parameters.AddWithValue("@quantity", itm.ingredientQuantity.ToString()); con.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { result = true; } else { MessageBox.Show("Failed to add..!", "Error"); } } catch (Exception e) { if (e.ToString().Contains("Violation of PRIMARY KEY constraint")) { MessageBox.Show("Already Exist !", "Error"); } else { MessageBox.Show(e.ToString(), "Error"); } } finally { con.Close(); } return(result); }