public async Task <IActionResult> Edit(string id, CancellationToken token) { var role = await _roleManager.FindByIdAsync(id); var members = new List <ApplicationUser>(); var nonMember = new List <ApplicationUser>(); var company = await GetCompany(token); var allUsers = await _userManager.Users.ToArrayAsync(token); var companyMembers = await _companyMemberRepository.FindByCompanyIdAsync(company.Id, token); var users = companyMembers.Select(companyMember => allUsers.Single(p => p.Id == companyMember.UserId)).ToList(); foreach (var user in users) { var list = await _userManager.IsInRoleAsync(user, role.Name) ? members : nonMember; list.Add(user); } return(View(new EditRoleVm { Role = role, Members = members, NonMembers = nonMember })); }
// GET: /<controller>/ public async Task <ViewResult> Index(CancellationToken token) { var company = await GetCompany(token); var allUsers = await _userManager.Users.ToArrayAsync(token); var companyMembers = await _companyMemberRepository.FindByCompanyIdAsync(company.Id, token); var users = companyMembers.Select(companyMember => allUsers.Single(p => p.Id == companyMember.UserId)).ToList(); return(View(users)); }