Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to list AbpUsers? #431


User avatar
0
joemo created

How can I retrieve a list of AbpUsers users, preferably async? For example, to populate a dropdown list of users to assign a task to. I've tried using UserManager _userManager but it only seems relevant to finding or retrieving one users' details at a time. Is there an IQueryable collection of users? I'd like to be able to then filter that list based on roles

:roll:


2 Answer(s)
  • User Avatar
    0
    joemo created

    Well, for future civilizations, here's how I did it.

    Added userRepository to the constructor in UserStore.cs:-

    _userRepository = userRepository;
    

    And added a function to retrieve the list asyncronously:

    public async Task<List<User>> GetAllUsersAsync()
            {
                return await _userRepository.GetAllListAsync();
            }
    

    Then you can get to it via an app service:-

    public async Task<GetAllUsersOutput> GetAllUsers()
            {
                return new GetAllUsersOutput
                {
                    Users = Mapper.Map<List<UserDto>>(await _userStore.GetAllUsersAsync())
                };
            }
    

    And use angular...

    vm.users = [];
    
                userService.getAllUsers().success(function (data) {
                    vm.users = data.users;
                });
    

    ... to display it in a view:-

    <select ng-model="vm.users.name" ng-options="user.id as user.name for user in vm.users">
                        <option value=""></option>
                    </select>
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you for sharing your code :)