Beispiel #1
0
        public ActionResult Edit(int id)
        {
            Picture picture = db.Pictures.Single(c => c.PictureId == id);
            PictureViewModel model = new PictureViewModel
            {
                PictureId = picture.PictureId,
                ImageUrl = picture.ImageUrl,
                Description = picture.Description,
                CategoryId = picture.CategoryId
            };

            ViewBag.CategoryId = new SelectList(db.Categories.ToList(), "CategoryId", "Name", selectedValue:picture.CategoryId);
            return View(model);
        }
Beispiel #2
0
        public ActionResult Create(PictureViewModel model)
        {
            if (ModelState.IsValid)
            {
                Picture picture = new Picture
                {
                    ImageUrl = model.ImageUrl,
                    CategoryId = model.CategoryId,
                    Description = model.Description
                };

                db.AddPicture(picture);

                return RedirectToAction("Index", "Home");
            }

            ViewBag.CategoryId = new SelectList(db.Categories.ToList(), "CategoryId", "Name");
            return View(model);
        }