//public Object Get(int page = 0, int pageSize = 10) //{ // IQueryable<Course> query; // query = Repository.GetAllCourses().OrderBy(c => c.CourseSubject.Id); // var totalCount = query.Count(); // var totalPages = (int)Math.Ceiling((double)totalCount / pageSize); // var urlHelper = new UrlHelper(Request); // var prevLink = page > 0 ? urlHelper.Link("Courses", new { page = page - 1 }) : ""; // var nextLink = page < totalPages - 1 ? urlHelper.Link("Courses", new { page = page + 1 }) : ""; // var results = query // .Skip(pageSize * page) // .Take(pageSize) // .ToList() // .Select(s => TheModelFactory.Create(s)); // return new // { // TotalCount = totalCount, // TotalPages = totalPages, // PrevPageLink = prevLink, // NextPageLink = nextLink, // Results = results // }; //} public IEnumerable <StudentBaseModel> Get(int page = 0, int pageSize = 10) { IQueryable <Student> query; query = Repository.GetAllStudentsWithEnrollments().OrderBy(c => c.LastName); var totalCount = query.Count(); var totalPages = (int)Math.Ceiling((double)totalCount / pageSize); var urlHelper = new UrlHelper(Request); var prevLink = page > 0 ? urlHelper.Link("Students", new { page = page - 1, pageSize = pageSize }) : ""; var nextLink = page < totalPages - 1 ? urlHelper.Link("Students", new { page = page + 1, pageSize = pageSize }) : ""; var paginationHeader = new { TotalCount = totalCount, TotalPages = totalPages, PrevPageLink = prevLink, NextPageLink = nextLink }; System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader)); var results = query .Skip(pageSize * page) .Take(pageSize) .ToList() .Select(s => TheModelFactory.CreateSummary(s)); return(results); }
public IHttpActionResult Get(int page = 0, int pageSize = 10) { IQueryable <Student> query; query = TheRepository.GetAllStudentsWithEnrollments().OrderBy(s => s.UserName); var totalCount = query.Count(); var totalPages = (int)Math.Ceiling((double)totalCount / pageSize); var urlHelper = new UrlHelper(Request); var prevLink = page > 0 ? urlHelper.Link("StudentsList", new { page = page - 1 }) : ""; var nextLink = page < totalPages - 1 ? urlHelper.Link("StudentsList", new { page = page + 1 }) : ""; var result = query .Skip(page * pageSize) .Take(pageSize) .ToList() .Select(s => TheModelFactory.CreateSummary(s)); return(Ok(new { TotalCount = totalCount, TotalPages = totalPages, PrevPageLink = prevLink, NextPageLink = nextLink, Results = result })); }
public IHttpActionResult Get(int courseID, int page = 0, int pageSize = 10) { IQueryable <Student> query; query = TheRepository.GetEnrolledStudentsInCourse(courseID).OrderBy(s => s.FirstName); var totalCount = query.Count(); var result = query.Skip(page * pageSize) .Take(pageSize).ToList().Select(s => TheModelFactory.CreateSummary(s)); return(Ok(result)); }
public object Get(DateTime diaryid) { try { var diary = TheRepo.GetDiary(_identityService.CurrentUser, diaryid); if (diaryid == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(TheModelFactory.CreateSummary(diary)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IEnumerable <StudentBaseModel> Get(int courseId, int page = 0, int pageSize = 10) { IQueryable <Student> query; query = TheRepository.GetEnrolledStudentsInCourse(courseId).OrderBy(s => s.LastName); var totalCount = query.Count(); System.Web.HttpContext.Current.Response.Headers.Add("X-InlineCount", totalCount.ToString()); var results = query .Skip(page * pageSize) .Take(pageSize) .Select(s => TheModelFactory.CreateSummary(s)); return(results); }
public HttpResponseMessage Get(DateTime orderId) { try { var order = TheRepository.GetOrder(_identityService.CurrentUser, orderId); if (order == null) { Request.CreateResponse(HttpStatusCode.NotFound); } return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.CreateSummary(order))); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Get(DateTime diaryId) { try { var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryId); if (diary == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Could not find diary")); } return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.CreateSummary(diary))); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Get(DateTime date) { try { string username = _identityService.CurrentUser; Diary diary = TheRepository.GetDiary(username, date); if (diary == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No diary found")); } DiarySummaryModel diarySummaryModel = TheModelFactory.CreateSummary(diary); return(Request.CreateResponse(HttpStatusCode.OK, diarySummaryModel)); } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception)); } }