public IActionResult All(int page = 1) { var viewModel = new DepartmentsListingViewModel() { Departments = departmentsService.All(ItemsPerPage, (page - 1) * ItemsPerPage).Select(x => new DepartmentViewModel { Id = x.Id, Name = x.Name, Email = x.Email, }), }; int count = this.departmentsService.Count(); viewModel.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage); if (viewModel.PagesCount == 0) { viewModel.PagesCount = 1; } viewModel.CurrentPage = page; return(this.View(viewModel)); }