public IHttpActionResult AllPosts(AllPostRequestModel postRequest) { if (postRequest.ValidateRequest(this, ModelState)) { ApiResponse.HttpStatusCode = HttpStatusCode.OK; var totalPages = Math.Ceiling((double)_db.Posts.Count() / (int)postRequest.PageSize); var dataList = new Dictionary<string, object>(); dataList.Add("posts", _db.Posts.OrderByDescending(p => p.Created) .Skip(((int)postRequest.PageNumber - 1) * (int)postRequest.PageSize) .Take((int)postRequest.PageSize) .Select(p => new { p.ID, p.Title, p.Content, p.Created, p.Visible, p.Attachment }).ToList() ); dataList.Add("totalPages", totalPages); ApiResponse.Data = dataList; } return ResponseContent(ApiResponse); }
public IHttpActionResult GetTotalPages(AllPostRequestModel postRequest) { if (postRequest.ValidateRequest(this, ModelState)) { ApiResponse.HttpStatusCode = HttpStatusCode.OK; ApiResponse.Data = new { totalPages = Math.Ceiling((double)_db.Posts.Count() / (int)postRequest.PageSize) }; } return ResponseContent(ApiResponse); }