Пример #1
0
        public ActionResult Create(Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                recipe.DateAdded = DateTime.Now;
                _recipeRepository.InsertOrUpdate(recipe);
                _recipeRepository.Save();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryId = new SelectList(_categoryRepository.All, "CategoryId", "Name", recipe.CategoryId);
            return View(recipe);
        }
Пример #2
0
 public void InsertOrUpdate(Recipe recipe)
 {
     if (recipe.RecipeId == default(int))
     {
         // New entity
         context.Recipes.Add(recipe);
     }
     else
     {
         // Existing entity
         context.Entry(recipe).State = EntityState.Modified;
         foreach (var image in recipe.Images)
         {
             if (image.ImageId == default(int))
             {
                 context.Images.Add(image);
             }
             else
             {
                 context.Entry(image).State = EntityState.Modified;
             }
         }
     }
 }
Пример #3
0
 public ActionResult Edit(Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         //db.Entry(recipe).State = EntityState.Modified;
         //db.SaveChanges();
         _recipeRepository.InsertOrUpdate(recipe);
         _recipeRepository.Save();
         return RedirectToAction("Index");
     }
     ViewBag.CategoryId = new SelectList(_categoryRepository.All, "CategoryId", "Name", recipe.CategoryId);
     return View(recipe);
 }