public ActionResult Create(VSong song)
        {
            try
            {
                var newsong = Newsong(song);
                db.Song.Add(newsong);
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                ViewBag.SongArtistID = new SelectList(db.Artist, "ArtistID", "ArtistName");
                ViewBag.SongExtensionID = new SelectList(db.Extension, "ExtensionID", "ExtensionName");
                ViewBag.SongGenreID = new SelectList(db.Genre, "GenreID", "GenreName");
                ViewBag.SongLanguageID = new SelectList(db.Language, "LanguageID", "LanguageName");
                return View();
            }
        }
 private Song Newsong(VSong song)
 {
     Song newsong = new Song
                        {
                            SongName = song.SongName,
                            Artist = song.Artist,
                            Extension = db.Extension.FirstOrDefault(p => p.ExtensionID == song.SongExtensionID),
                            Genre = db.Genre.FirstOrDefault(p => p.GenreID == song.SongGenreID),
                            Language = db.Language.FirstOrDefault(p => p.LanguageID == song.SongLanguageID),
                            SongID = song.SongID,
                            SongIntonation = song.Intonation,
                            SongTone = song.Tone,
                            SongRhythm = song.Rhythm,
                            SongPath = song.FliePath,
                            SongArtistID = song.SongArtistID,
                            SongLanguageID = song.SongLanguageID,
                            SongGenreID = song.SongGenreID,
                            SongExtensionID = song.SongExtensionID
                        };
     return newsong;
 }
 public ActionResult Details(Guid id)
 {
     Song song = db.Song.Find(id);
    VSong vSong = new VSong(song);
    return View(vSong);
 }
        public ActionResult Delete(Guid id, FormCollection collection)
        {
            try
            {
                Song song = db.Song.Find(id);
                string filePath = Server.MapPath(song.SongPath);
                FileInfo file = new FileInfo(filePath);
                if (file.Exists)
                {
                    file.Delete(); //删除单个文件
                }
                db.Song.Remove(song);
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                Song song = db.Song.Find(id);
                VSong vSong = new VSong(song);
                return View(vSong);
            }
        }
        public ActionResult Edit(VSong vSong)
        {
            try
            {
                var newsong = Newsong(vSong);
                db.Entry(newsong).State = EntityState.Modified;
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {

                ViewBag.SongArtistID = new SelectList(db.Artist, "ArtistID", "ArtistName");
                ViewBag.SongExtensionID = new SelectList(db.Extension, "ExtensionID", "ExtensionName");
                ViewBag.SongGenreID = new SelectList(db.Genre, "GenreID", "GenreName");
                ViewBag.SongLanguageID = new SelectList(db.Language, "LanguageID", "LanguageName");
                
                return View(vSong);
            }
        }
        //
        // GET: /VSong/Edit/5

        public ActionResult Edit(Guid id)
        {
            Song song = db.Song.Find(id);
            ViewBag.SongArtistID = new SelectList(db.Artist, "ArtistID", "ArtistName", song.SongArtistID);
            ViewBag.SongExtensionID = new SelectList(db.Extension, "ExtensionID", "ExtensionName", song.SongExtensionID);
            ViewBag.SongGenreID = new SelectList(db.Genre, "GenreID", "GenreName", song.SongGenreID);
            ViewBag.SongLanguageID = new SelectList(db.Language, "LanguageID", "LanguageName", song.SongLanguageID);
            VSong vSong = new VSong(song);
            return View(vSong);
        }