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 totalStudents = await _studentsRepository.CountAsync(); var totalPages = (int)Math.Ceiling((double)totalStudents / pageSize); IEnumerable <Student> students = _studentsRepository .GetAll() .OrderBy(s => s.ID) .Skip((currentPage - 1) * currentPageSize) .Take(currentPageSize) .ToList(); Response.AddPagination(page, pageSize, totalStudents, totalPages); IEnumerable <StudentViewModel> studentsVM = Mapper.Map <IEnumerable <Student>, IEnumerable <StudentViewModel> >(students); return(new OkObjectResult(studentsVM)); }