Open Closed

List of AppUser #1258


0
cellero created
  • ABP Framework version: v4.3.0
  • UI type: Blazor Server
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): No

Hopefully this is a simple question. I need a list of App Users in a role in .razor.cs.

I can get this for the Current User is ok like this: @using Volo.Abp.Users @inject ICurrentUser CurrentUser .... bool isAdmin = CurrentUser.IsInRole("admin");

Can you please provide some sample code has to how to get a List<AppUser>()

Thank you.


1 Answer(s)
  • 0
    liangshiwei created
    Support Team

    Hi,

    You just need to use IRepository to get users.

    Example:

    public class UserAppService : ApplicationService, IUserAppService
    {
        private readonly IRepository<AppUser, Guid> _appUserRepository;
        
        public UserAppService(IRepository<AppUser, Guid> appUserRepository)
        {
            appUserRepository = _appUserRepository;
        }
        
        public async Task<List<AppUserDto>> GetUserList()
        {
            return ObjectMapper.Map<AppUser,AppUserDto>(await _appUserRepository.GetListAsync());
        }
    }
    
    public partial class Index
    {
        [Inject]
        protected IUserAppService UserAppService { get; set; }
    
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            var users = await UserAppService.GetUserList();
            await base.OnAfterRenderAsync(firstRender);
        }
    }