コード例 #1
0
        public ActionResult <MyResponse> DeleteIngredient(int id)
        {
            MyResponse response = _ingredientsService.DeleteIngredient(id, GetUserId());

            if (response.IsFailed())
            {
                Response.StatusCode = 400;
            }
            return(response);
        }
コード例 #2
0
        public ActionResult <MyResponse> PutRecipe([FromBody] Recipe recipe)
        {
            MyResponse response = _recipesService.UpdateRecipe(recipe, GetUserId());

            if (response.IsFailed())
            {
                Response.StatusCode = 400;
            }
            return(response);
        }
コード例 #3
0
        public ActionResult <MyResponse> PutIngredient([FromBody] Ingredient ingredient)
        {
            MyResponse response = _ingredientsService.UpdateIngredient(ingredient, GetUserId());

            if (response.IsFailed())
            {
                Response.StatusCode = 400;
            }
            return(response);
        }
コード例 #4
0
    public MyResponse UpdateRecipeWithIngredients(RecipeWithIngredients recipeWithIngredients, string userId)
    {
        MyResponse updateResult = UpdateRecipe(recipeWithIngredients.Recipe, userId);

        if (updateResult.IsFailed())
        {
            return(updateResult);
        }

        List <Ingredient> dbIngredients = _ingredientsRepository.GetIngredientsForRecipe(recipeWithIngredients.Recipe.Id);

        UpdateOrAddIngredientsToRecipe(recipeWithIngredients.Ingredients, dbIngredients, recipeWithIngredients.Recipe.Id);
        DeleteRemainingIngredients(recipeWithIngredients.Ingredients, dbIngredients);
        return(updateResult);
    }