Uwe Jaedick

Uwe Jaedick

  • NA
  • 2
  • 818

Microsoft Identity Management and Entity Framework Core

Jun 12 2023 3:44 AM

I am trying to develop a maintenance page to add users and roles and asign roles to users. Hence I like to show all roles asigned t o a userprofile.

1.) Select a userprofile from the grid and show userid in header for roleuser grid

@inject UserManager<IdentityUser> UserManager
:

private List<RoleUserModel>? userRoles = null;

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

    }

2.) Selecting the users roles to show them in a separate grid / list
    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 CS1503

        IList<string> usrRoles = await UserManager.GetRolesAsync(userId);
        userRoles = await RoleUserService.GetUserRolesAsync(usrRoles); // Error CS0266
    }

3.) Models:   

public class RoleUserModel
    {
        public string UserId { get; set; }
        public string RoleId { get; set; }
    }

4.) The code was copied from the Microsoft learning page and should work. Same could is available in stackoverflow and should work! As you can see it is not working but throwing errors. I could need some help to solve the error (One of the 4 attempts should be working)


Answers (1)