// // 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); }
// // 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) { try { //Save Album storeDB.AddToAlbums(album); storeDB.SaveChanges(); return Redirect("/"); } catch { //Invalid - redisplay with errors var viewModel = new StoreManagerViewModel { Album = album, Genres = storeDB.Genres.ToList(), Artists = storeDB.Artists.ToList() }; return View(viewModel); } }
public ActionResult Edit(int id, FormCollection formValues) { var album = storeDB.Albums.Single(a => a.AlbumId == id); try { //Save Album UpdateModel(album, "Album"); storeDB.SaveChanges(); return RedirectToAction("Index"); } catch { var viewModel = new StoreManagerViewModel { Album = album, Genres = storeDB.Genres.ToList(), Artists = storeDB.Artists.ToList() }; return View(viewModel); } }