コード例 #1
0
        public ActionResult CreateSong(Song song)
        {
            if (ModelState.IsValid == false)
            {
                TempData.FlashError("Whoops!", "There seems to be some problems with the information you provided. Please correct the errors and try again.");
                return View(song);
            }

            _session.Store(song);
            TempData.FlashSuccess(song.Title + " created", "The new song resource was added successfully.");
            return RedirectToAction("SongDetails", new { id = song.Id });
        }
コード例 #2
0
        public ActionResult EditSong(Song song)
        {
            if (ModelState.IsValid == false)
            {
                TempData.FlashError("Whoops!", "There seems to be some problems with the information you provided. Please correct the errors and try again.");
                return View(song);
            }

            var songToUpdate = _session.Load<Song>(song.Id);
            if (songToUpdate == null)
                return new HttpNotFoundResult();

            songToUpdate.Title = song.Title;
            songToUpdate.Artist = song.Artist;
            songToUpdate.Album = song.Album;

            _session.SaveChanges();
            TempData.FlashSuccess("Changes saved to " + song.Title, "The song has been updated with your changes.");

            return RedirectToAction("SongDetails", new {id = song.Id});
        }