Leftyx/AspNetIdentityCustomDb

List of Users/Roles

nbinobied opened this issue · 1 comments

Hello,
I have an implementation of this project for my work and I'm facing a difficulty in retrieving the list of users/roles from the local DB to create a table of users and assigned roles.

I've tried to create a ToList() function in the UserStore class but I'm unable to access the UserStore in the controller, UserManager doesn't have any implementation of custom functions.

I've also tried to retrieve the list of users through the IEnumerator from the UserManager, but I'm getting an error (the error comes from the Users object UserManager.Users.GetEnumerator():

System.NotSupportedException: 'Store does not implement IQueryableUserStore.'

Here is the code of the controller that I'm trying to use:

        //
        // GET: /Account/Users
        [Authorize(Roles = "Administrators")]
        public ActionResult Users()
        {
            var EnumeratorUsers = UserManager.Users.GetEnumerator();
            
            List<User> users = new List<User>();
            while (EnumeratorUsers.MoveNext() == true)
            {
                users.Add(EnumeratorUsers.Current);
            }

            return View(users);
        }```

I was able to solve this issue by implementing IQueryableUserStore<User, int> into the UserStore and implementing the method public IQueryable<User> Users => (UserDb.TryLoadData()).AsQueryable(); then call the var List = UserManager.Users.ToList(); in the controller.