public async Task <IActionResult> Get() { var pagination = Request.Headers["Pagination"]; if (!string.IsNullOrEmpty(pagination)) { string[] vals = pagination.ToString().Split(','); int.TryParse(vals[0], out page); int.TryParse(vals[1], out pageSize); } int currentPage = page; int currentPageSize = pageSize; var totalCourses = await _coursesRepository.CountsAsync(); var totalPages = (int)Math.Ceiling((double)totalCourses / pageSize); IEnumerable <Course> courses = _coursesRepository .AllIncluding(c => c.Department) .OrderBy(c => c.CourseID) .Skip((currentPage - 1) * currentPageSize) .Take(currentPageSize) .ToList(); Response.AddPagination(page, pageSize, totalCourses, totalPages); IEnumerable <CourseViewModel> coursesVM = Mapper.Map <IEnumerable <Course>, IEnumerable <CourseViewModel> >(courses); return(Ok(coursesVM)); }