/// <summary>
 /// Fills current instance with data provided by users in role collection
 /// </summary>
 /// <param name="usersInRoles"> The users in roles. </param>
 public void SetFromUsers(IEnumerable <UserInRoleDto> usersInRoles)
 {
     foreach (var user in usersInRoles)
     {
         if (user.RoleIds.Contains(Id))
         {
             UsersInRole.Add(UserViewModel.From(user));
         }
         else
         {
             UsersOutsideRole.Add(UserViewModel.From(user));
         }
     }
 }
Exemple #2
0
        private async Task populateList(string roleId)
        {
            var role = await roleManager.FindByIdAsync(roleId);

            RoleName = role.Name;
            RoleId   = role.Id;


            //Got error: There is already an open DataReader associated with this Command which must be closed first.
            foreach (var user in userManager.Users.ToList())
            {
                if (await userManager.IsInRoleAsync(user, RoleName))
                {
                    UsersInRole.Add(user);
                }
            }

            //Users to be added shouldn't be in the role already:
            UserList = new SelectList(userManager.Users.Where(u => !UsersInRole.Contains(u)).ToList(), "Id", "UserName");
        }