public async Task <ActionResult> Index(string searchText, int?page) { var totalUsers = await _applicationUserRepository.GetTotalCountAsync(); Pager pager = new Pager(totalUsers, page); var users = _applicationUserRepository.GetAll(searchText) .Skip((pager.CurrentPage - 1) * pager.PageSize) .Take(pager.PageSize) .Select(u => new ApplicationUserDto() { Id = u.Id, UserName = u.UserName, FirstName = u.FirstName, LastName = u.LastName, Email = u.Email }); var viewModel = new ApplicationUserIndexViewModel() { Users = users, Pager = pager, SearchText = searchText }; return(View(viewModel)); }
public async Task <IActionResult> Index(string option = null, string search = null) { //data ophalen joins var lst = from u in _context.Users join ur in _context.UserRoles on u.Id equals ur.UserId join r in _context.Roles on ur.RoleId equals r.Id select new { u.UserName, u.Voornaam, u.Achternaam, u.Id, r.Name }; //viewmodel initialisersn List <ApplicationUserIndexViewModel> lijstUserMetRoles = new List <ApplicationUserIndexViewModel>(); //opvullen van viewmodel met data foreach (var item in lst) { ApplicationUserIndexViewModel u = new ApplicationUserIndexViewModel { Username = item.UserName, UserId = item.Id, Voornaam = item.Voornaam, Achternaam = item.Achternaam, Rol = item.Name }; lijstUserMetRoles.Add(u); } return(View(lijstUserMetRoles)); }