I am using Identity in a project that has extended properties In ApplicationUser class as OrganisationId.
I am using ApplicationUserManager to read user details.
here is my ApplicationUser class:
public class ApplicationUser
: IdentityUser<int, ApplicationUserLogin,
ApplicationUserRole, ApplicationUserClaim>, IUser<int>
{
public async Task<ClaimsIdentity>
GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
userIdentity.AddClaim(new Claim("OrganisationId", OrganisationId.ToString()));
return userIdentity;
}
public int OrganisationId { get; set; }
}
And in the AccountController class I inject the ApplicationUserManager object.
Then user manager object gives me a way to find whether a user in role or not.
var isUserAdmin = await _userManager.IsInRoleAsync(userId, adminRoleName);
But what I need is a way to find all users whom has admin rights in an organisation.
Something like this:
_userManager.Users.Where(u=>u.OrganisationId=1 && u.Roles.Contains(adminRole))
But this doesnt work as Roles is collection of ApplicationUserRole.
Any idea how I could manage to get all the admin users in an organisation?