Reputation: 350
If I have a list of user types (both ID and name), how can I get the users that belong to that user type (not members)? There doesn't seem to be any methods for User[] userList = User.Get ByType
Upvotes: 3
Views: 1960
Reputation: 1178
You can do it using IDs like this:
var userType = UserType.GetUserType(1);
var users = User.getAll().Where(u => u.UserType == userType);
Upvotes: 1
Reputation: 10942
Using linq you should be able to get what you're looking for. Here's an example of how to get Users based solely on the alias of the User Type:
string[] userTypeAliases = new string[] { "writer", "editor" };
var userTypes = umbraco.BusinessLogic.UserType.GetAllUserTypes()
.Where(ut => userTypeAliases.Contains(ut.Alias));
var users = umbraco.BusinessLogic.User.getAll()
.Where(u => userTypes.Contains(u.UserType));
Upvotes: 3