// GET: Songs/Details public ActionResult Details(int?id) { if (id == null) { this.AddNotification("Song does not exist", NotificationType.ERROR); return(RedirectToAction("MySongs")); } Song song = db.Songs .Where(s => s.Id == id) .Include(s => s.Uploader) .Include(s => s.Tags) .First(); if (song == null) { this.AddNotification("Song does not exist", NotificationType.ERROR); return(RedirectToAction("MySongs")); } SongDetailsModel currSong = new SongDetailsModel(); currSong.Id = song.Id; currSong.Artist = song.Artist; currSong.Title = song.Title; currSong.Genre = db.Genres.Where(g => g.Id == song.GenreId).Select(g => g.Name).First(); currSong.Description = song.Description; currSong.UploadDate = song.UploadDate; currSong.Uploader = song.Uploader; currSong.Tags = song.Tags.ToList(); return(View(currSong)); }
public ActionResult Details(int?id) { if (id == null) { return(HttpNotFound()); } using (var db = new MusicStationDbContext()) { var song = db.Songs .Where(s => s.Id == id) .Include(s => s.User) .FirstOrDefault(); if (song == null) { return(HttpNotFound()); } var model = new SongDetailsModel { Artist = song.Artist, Title = song.Title, Details = song.Details, Genre = song.Genre, ImagePath = song.ImagePath, FilePath = song.FilePath, Id = song.Id, User = song.User }; return(View(model)); } }