コード例 #1
0
        public ActionResult PutInRecipe([FromBody] UsedIngredientsDTO ingredientDto)
        {
            if (IngredientsDAO.UpdateInRecipe(ingredientDto))
            {
                return(Ok());
            }

            return(BadRequest());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public UsedIngredientsDTO PostToRecipe([FromBody] UsedIngredientsDTO ingredientDto)
 {
     return(IngredientsDAO.PostToRecipe(ingredientDto));
 }