public HttpResponseMessage GetResources() { using (OnlineMusicEntities db = new OnlineMusicEntities()) { var list = songDto.GetSongQuery(db, s => s.Privacy == false && s.Verified == true && s.Official == true).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, list)); } }
public HttpResponseMessage GetMediaUploaded([FromUri] int id) { using (var db = new OnlineMusicEntities()) { var user = (from u in db.Users where u.Id == id select u).FirstOrDefault(); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không tìm thấy user id=" + id)); } var query = songDto.GetSongQuery(db, song => song.AuthorId == id); var list = query.OrderByDescending(song => song.UploadedDate) .ThenBy(song => song.Verified) .ThenBy(song => song.Privacy).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, list)); } }
public HttpResponseMessage GetAllSongs(string type = "audio") { using (var db = new OnlineMusicEntities()) { IQueryable <SongModel> query = null; if (String.Compare(type, "audio", true) == 0) { query = dto.GetSongQuery(db, (song) => song.Resource.Type == (int)ResourceTypeManager.Audio); } else if (String.Compare(type, "video", true) == 0) { query = dto.GetSongQuery(db, (song) => song.Resource.Type == (int)ResourceTypeManager.Video); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Resource type not supported")); } ICollection <SongModel> listSongs; listSongs = query.OrderByDescending(s => s.UploadedDate).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, listSongs)); } }