public HttpResponseMessage GetSongsOfAlbum([FromUri] int id) { using (var db = new OnlineMusicEntities()) { var album = (from a in db.Albums where a.Id == id select a).FirstOrDefault(); if (album == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không tìm thấy album id=" + id)); } var listSongs = songDto.ConvertToSongModel(album.Songs.Where(s => s.Verified == true && s.Privacy == false && s.Official == true).ToList()); return(Request.CreateResponse(HttpStatusCode.OK, listSongs)); } }
public HttpResponseMessage GetSongsOfArtist([FromUri] int id, bool verified = true) { using (var db = new OnlineMusicEntities()) { Artist artist = (from a in db.Artists where a.Id == id && a.Verified == verified select a).FirstOrDefault(); if (artist == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không tìm thấy nghệ sĩ id=" + id)); } ICollection <SongModel> listSongs = songDto.ConvertToSongModel(artist.Songs.Where(s => s.Verified == true && s.Privacy == false && s.Official == true).ToList()).OrderByDescending(s => s.Views).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, listSongs)); } }