示例#1
0
        public async Task <IActionResult> Add(Recipe recipe)
        {
            var ingredients  = recipe.Ingredients;
            var instructions = recipe.Instructions;

            recipe.Instructions = null;
            recipe.Ingredients  = null;
            recipe.Author       = User.Identity.Name;
            await _Recipe.CreateRecipe(recipe);

            foreach (var ingredient in ingredients)
            {
                ingredient.RecipeID = recipe.ID;
                await _Ingredient.CreateIngredient(ingredient);
            }
            foreach (var instruction in instructions)
            {
                instruction.RecipeID = recipe.ID;
                await _Instruction.CreateInstruction(instruction);
            }
            return(RedirectToAction("Index", "Home"));
        }