コード例 #1
0
        public ActionResult Create(Recipe recipe, IEnumerable<Ingredient> ingredients, IEnumerable<Step> steps)
        {
            if (ModelState.IsValid)
            {
                _dbRecipe.Recipes.Add(recipe);
                _dbRecipe.SaveChanges();

                if (steps != null)
                {
                    foreach (var step in steps)
                    {
                        _dbStep.Steps.Add(step);
                        _dbStep.SaveChanges();
                    }
                }

                if (ingredients != null)
                {
                    foreach (var ingredient in ingredients)
                    {
                        _dbIngredient.Ingredients.Add(ingredient);
                        _dbIngredient.SaveChanges();
                    }
                }

                return RedirectToAction("Index");
            }

            return View(recipe);
        }
コード例 #2
0
 public ActionResult Edit(Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         _dbRecipe.Entry(recipe).State = EntityState.Modified;
         _dbRecipe.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(recipe);
 }