Пример #1
0
        public IActionResult Add3(RecipeVM vm)
        {
            // Get the current values from Session
            Recipe recipeInProgress = GetRecipeInProgress();

            // Validate the fields that are on this form.  If they're no good, no sense in continuing
            string[] fieldsToValidate =
            {
                "Recipe.Steps",
            };
            if (AnyInvalid(fieldsToValidate))
            {
                // If there are any validation errors, re-show the view to the user
                vm.Recipe = recipeInProgress;
                CreateSelectLists(vm);
                return(View(vm));
            }

            // Apply values from this view to the one in the cart
            recipeInProgress.Steps = vm.Recipe.Steps;

            // Save the recipe
            int recipeId = recipeDAO.CreateRecipe(recipeInProgress);

            // Clear the Session recipe
            ClearRecipeInProgress();

            // Go to the next view
            return(RedirectToAction("AddConfirmation", "Recipe", new { id = recipeId }));
        }
        public ActionResult <Recipe> AddRecipe([FromBody] Recipe recipe)
        {
            bool worked = dao.CreateRecipe(recipe);

            if (worked)
            {
                return(CreatedAtRoute("GetRecipeById", new { id = recipe.Id }, recipe));
            }
            return(null);
        }
Пример #3
0
        public IActionResult Add3(Recipe recipe)
        {
            // Get the current values from Session
            Recipe recipeInProgress = GetRecipeInProgress();

            // TODO: How to Validate?

            // Apply values from this view to the one in the cart
            recipeInProgress.Steps = recipe.Steps;

            // Save the recipe
            int recipeId = recipeDAO.CreateRecipe(recipeInProgress);

            // Clear the Session recipe
            ClearRecipeInProgress();

            // Go to the next view
            return(RedirectToAction("AddConfirmation", "Home", new { id = recipeId }));
        }