public ActionResult PutInRecipe([FromBody] UsedIngredientsDTO ingredientDto) { if (IngredientsDAO.UpdateInRecipe(ingredientDto)) { return(Ok()); } return(BadRequest()); }
public static UsedIngredientsDTO PostToRecipe(UsedIngredientsDTO ingredient) { using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = REQ_POST_TO_RECIPE; command.Parameters.AddWithValue($@"{FIELD_ID_RECIPE}", ingredient.IdRecipe); command.Parameters.AddWithValue($@"{FIELD_ID_INGREDIENT}", ingredient.IdIngredient); command.Parameters.AddWithValue($@"{FIELD_QUANTITY}", ingredient.Quantity); command.Parameters.AddWithValue($@"{FIELD_UNIT}", ingredient.Unit); command.ExecuteNonQuery(); } return(ingredient); }
public static bool UpdateInRecipe(UsedIngredientsDTO ingredient) { bool hasBeenChanged = false; using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = REQ_UPDATE_IN_RECIPE; command.Parameters.AddWithValue($"{FIELD_ID_RECIPE}", ingredient.IdRecipe); command.Parameters.AddWithValue($"{FIELD_ID_INGREDIENT}", ingredient.IdIngredient); command.Parameters.AddWithValue($"{FIELD_QUANTITY}", ingredient.Quantity); command.Parameters.AddWithValue($"{FIELD_UNIT}", ingredient.Unit); hasBeenChanged = command.ExecuteNonQuery() == 1; } return(hasBeenChanged); }
public UsedIngredientsDTO PostToRecipe([FromBody] UsedIngredientsDTO ingredientDto) { return(IngredientsDAO.PostToRecipe(ingredientDto)); }