Example #1
0
        //
        // GET: /Recipe/Create
        public ActionResult Create()
        {
            ViewBag.PossibleCategories = _categoryRepository.All;
            Recipe recipe = new Recipe
                                {
                                    Images = new[]
                                                 {
                                                     new Image{Delete = false,FullSizePath = "/Uploads/Images/p16h1uc1v21bjhu401osqgot18ig4.jpg",OrigFileName = "blala.jpg"},
                                                     new Image{Delete = false,FullSizePath = "/Uploads/Images/p16h9e771accp3bd1ohojbfmmq4.jpg",OrigFileName = "blibli.jpg"}
                                                 }

                                };

            return View(recipe);
        }
Example #2
0
        public ActionResult Create(Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                foreach (var image in recipe.Images)
                {
                    image.Recipe = recipe;
                }
                _recipeRepository.InsertOrUpdate(recipe);
                _recipeRepository.Save();
                return RedirectToAction("Index");
            }

            ViewBag.PossibleCategories = _categoryRepository.All;
            return View(recipe);
        }
Example #3
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;
             }
         }
     }
 }