Base solution for your next web application
Open Closed

Users in organization unit #4134


User avatar
0
Ricavir created

Hi,

I want to retrieve users that are included in, at least, one organization unit. I've looked to abp docs but didn't found.

Right now, I'm using following code :

//Find users in OU
            foreach(var user in await UserManager.Users.ToListAsync())
            {
                if((await UserManager.GetOrganizationUnitsAsync(user)).Count() > 0)
                {
                    employeeIds.Add(user.Id);
                }
            }

Can I achieve that in a more efficient way ?


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Ricavir,

    You can find users in an organizaiton unit but there is no built-in method for your use case. You can write a custom repository or custom linq query to join "UserManager.Users" with "_organizationUnitRepository.GetAll()". Then, you can group it by user or you can distinct this list.

  • User Avatar
    0
    Ricavir created

    Thanks @ismcagdas