// // GET: /StoreManager/Create public ActionResult Create() { var viewModel = new StoreManagerViewModel { Album = new Album(), Genres = storeDB.Genres.ToList(), Artists = storeDB.Artists.ToList() }; return View(viewModel); }
public ActionResult Create(Album album) { if (ModelState.IsValid) { //Save Album storeDB.AddToAlbums(album); storeDB.SaveChanges(); return RedirectToAction("Index"); } // Invalid – redisplay with errors var viewModel = new StoreManagerViewModel { Album = album, Genres = storeDB.Genres.ToList(), Artists = storeDB.Artists.ToList() }; return View(viewModel); }
// // GET: /StoreManager/Edit/5 public ActionResult Edit(int id) { var viewModel = new StoreManagerViewModel { Album = storeDB.Albums.Single(a => a.AlbumId == id), Genres = storeDB.Genres.ToList(), Artists = storeDB.Artists.ToList() }; return View(viewModel); }