Ends in:
2 DAYS
4 HRS
40 MIN
46 SEC
Ends in:
2 D
4 H
40 M
46 S
Open Closed

List of AppUser #1258


User avatar
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.


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    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);
        }
    }
    
  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35