public virtual async Task RemoveMembersAsync(Guid id, OrganizationUnitRemoveMembersInput input)
        {
            var ou = await OrganizationUnitRepository.GetAsync(id, false);

            await AuthorizationService.CheckAsync(ou, CommonOperations.Update);

            var availableRoles = (await GetAvailableRolesAsync(ou.ParentId)).Select(r => r.Name).ToArray();

            foreach (var userId in input.UserIds)
            {
                var user = await UserManager.GetByIdAsync(userId);

                var userRoleNames = (await RoleRepository.GetListAsync())
                                    .Where(r => user.Roles.Select(ur => ur.RoleId).Contains(r.Id))
                                    .Select(r => r.Name).ToArray();


                await UserManager.SetRolesAsync(user, userRoleNames.Except(availableRoles));

                await UserManager.RemoveFromOrganizationUnitAsync(user, ou);
            }
        }
Example #2
0
 public async Task RemoveMembersAsync(Guid id, OrganizationUnitRemoveMembersInput input)
 {
     await _organizationUnitAppService.RemoveMembersAsync(id, input);
 }