Exemplo n.º 1
0
        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
            }));
        }
Exemplo n.º 2
0
        // 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));
        }