public async Task <IActionResult> Index(string country, string lastName, string firstName, string gender, int page = 1) { var countries = await _unitOfWork.CountryRepository.GetAllCountriesAsync(); countries.Insert(0, new Country { CountryName = "All countries" }); SelectList selectList = new SelectList(countries, "CountryName", "CountryName"); ViewBag.Countries = selectList; ViewBag.CurrentUsername = User.Identity.Name; var userFilterParams = new UserFilterParams { Country = string.IsNullOrEmpty(country) ? "All countries" : country, Gender = string.IsNullOrEmpty(gender) ? "Male or female" : gender, CurrentUsername = User.Identity.Name, FirstName = firstName, LastName = lastName }; var users = await _unitOfWork.UserRepository.GetUsersAsync(userFilterParams); int pageSize = 10; var count = users.Count(); var items = users.Skip((page - 1) * pageSize).Take(pageSize).ToList(); PageViewModel pageViewModel = new PageViewModel(count, page, pageSize); PaginatedUsersViewModel viewModel = new PaginatedUsersViewModel() { PageViewModel = pageViewModel, Users = items, Country = country, Gender = gender, CurrentUsername = User.Identity.Name, FirstName = firstName, LastName = lastName }; return(View(viewModel)); }
public async Task <IActionResult> Users([FromQuery] int pageSize = 5, [FromQuery] int pageIndex = 0) { var usersCount = await _context.UserInformation.LongCountAsync(); var users = await _context.UserInformation .OrderBy(c => c.FirstName) .Skip(pageSize * pageIndex) .Take(pageSize) .ToListAsync(); var model = new PaginatedUsersViewModel <UserInformation> { PageSize = pageSize, PageIndex = pageIndex, Count = usersCount, Data = users }; return(Ok(model)); }