Dropdown of users that have a specific role

I'm trying to get this working with out diving into the IDE too much. (I am fairly new to ef and linq syntax)
I've got an application with a couple Roles: Admin and Sales Manager.
In this application there is an Entity called "Store"

When creating a "Store" I would like to be able to select a Sales Manager for that store (which would be a userId on the Store Table). The idea is that only users that have the role of "Sales Manager" would populate in the dropdown field.

Any pointers would be greatly appreciated!

Hi @_Daniel,

This can be achieved with a custom method. Add it to the XXX.razor.cs file that Radzen has generated for your XXX page.

        public UserManager<ApplicationUser> UserManager { get; set; }

        public async Task<IEnumerable<ApplicationUser>> GetUsers(string role)
            var users = (await Security.GetUsers()).ToList();

            foreach (var user in users)
                user.RoleNames = await UserManager.GetRolesAsync(user);

            return users.Where(user => user.RoleNames.Contains(role));

Then invoke this method and set a property to it. This property can then be data-bound to a dropdown.

1 Like

Awesome! This works, one more question, instead of injecting it on every page is there a way to inject it so that it's accessible from any page?