public async Task <IActionResult> Edit(Recipe recipe) { var ingredients = recipe.Ingredients; var instructions = recipe.Instructions; recipe.Instructions = null; recipe.Ingredients = null; recipe = await _Recipe.UpdateRecipe(recipe); List <Ingredient> deleteIngredients = await _Ingredient.GetIngredients(recipe.ID); List <Instruction> deleteInstruction = await _Instruction.GetInstructions(recipe.ID); foreach (Ingredient ingredient in deleteIngredients) { await _Ingredient.DeleteIngredient(ingredient); } foreach (Instruction instruction in deleteInstruction) { await _Instruction.DeleteInstruction(instruction); } foreach (Ingredient ingredient in ingredients) { ingredient.RecipeID = recipe.ID; await _Ingredient.CreateIngredient(ingredient); } foreach (Instruction instruction in instructions) { instruction.RecipeID = recipe.ID; await _Instruction.CreateInstruction(instruction); } return(RedirectToAction("Index", "Home")); }