public ActionResult Create(Album album) { // TODO: Add insert logic here try { // TODO: Add insert logic here storeDB.AddToAlbums(album); storeDB.SaveChanges(); //return RedirectToAction("Index"); return Redirect("/"); } catch { // Invalid - redisplay with errors var viewModel = new StoreManagerViewModel { Album = album, 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); }
// // 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); }
public ActionResult Edit(int id, FormCollection collection) { var album = storeDB.Albums.Single(a => a.AlbumId == id); try { // TODO: SAVE UpdateModel(album, "Album"); // tự động update biến album vào table Album storeDB.SaveChanges(); return RedirectToAction("Index"); } catch { // Nếu lưu không được thì giữ lại toàn bộ thông tin. var viewModel = new StoreManagerViewModel { Album = album, Artists = storeDB.Artists.ToList(), Genres = storeDB.Genres.ToList() }; return View(viewModel); } }