await UserManager.GetRolesAsync()

64 Views Asked by At

I am trying to display all roles asigned to a user in order to delete or add new roles.

The page is loading all users into a grid (1) and all existing roles into a second grid (2). Selecting a user (click on row) triggers "private async Task SelectedRow(RowSelectEventArgs args)" and displays the users name in the grid (3) header.

Next steps would be selecting a role and clicking a button in the grid to transfer the role to the RoleUserGrid.

private List<RoleUserModel>? userRoles = null;

[Parameter]
public string Selection { get; set; }

[Parameter]
public string UserId { get; set; }

    private async Task SelectedRow(RowSelectEventArgs<UserModel> args) 
    {
        Selection = args.Data.UserName;
        UserId = args.Data.Id;

        var user = await UserManager.FindByNameAsync(Selection);
        var userId = await UserManager.FindByIdAsync(UserId);

        userRoles = await UserManager.GetRolesAsync(userId.Id); // Error CS1503
        userRoles = await UserManager.GetRolesAsync(Selection); // Error CS1503
        userRoles = await UserManager.GetRolesAsync(user);      // Error CS 1503

        IList<string> usrRoles = await UserManager.GetRolesAsync(userId);  // this works but ...
        // how do I get this into userRoles?
    }
0

There are 0 best solutions below