Lukas
Lukas

Reputation: 109

How to get user names containing string in email and having a particular role

I know how to get the users in role

_userManager.GetUsersInRoleAsync("RequiredRole");

but how to find users with a part of the string? Thanks in advance for your help.

Upvotes: 0

Views: 97

Answers (1)

Edward
Edward

Reputation: 30016

You could query the ApplicationUser list like below:

        var usersInRole = _userManager.GetUsersInRoleAsync("Test").Result;
        if(usersInRole.Count>0)
        {
            //replace u.UserName if you need other logic
            var users = usersInRole.Where(u => u.Email.Contains(u.UserName)).ToList();
        }

Upvotes: 1

Related Questions