Exemple #1
0
        public virtual async Task <PagedResultDto <IdentityUserDetailsDto> > GetListDetailsAsync(GetIdentityUsersDetailsInput input)
        {
            var query = await CreateFilteredQueryAsync(input);

            var count = await AsyncExecuter.CountAsync(query);

            query = query.PageBy(input.SkipCount, input.MaxResultCount);
            var list = await AsyncExecuter.ToListAsync(query);

            var userListDtos = ObjectMapper.Map <List <IdentityUser>, List <IdentityUserDetailsDto> >(list);

            await FillRoleNames(userListDtos);
            await FillOrganizationUnitNames(userListDtos);

            return(new PagedResultDto <IdentityUserDetailsDto>(
                       count,
                       userListDtos
                       ));
        }
Exemple #2
0
        public virtual async Task <IQueryable <IdentityUser> > CreateFilteredQueryAsync(GetIdentityUsersDetailsInput input)
        {
            var query = await _repository.WithDetailsAsync();

            if (input.OrganizationUnitId != null)
            {
                var code = await UnitManager.GetCodeOrDefaultAsync(input.OrganizationUnitId.Value);

                var organizationUnitIds = (await UnitManager.FindChildrenAsync(input.OrganizationUnitId.Value, true)).Select(x => x.Id).ToList();
                organizationUnitIds.Add(input.OrganizationUnitId.Value);
                query = query.Where(x => x.OrganizationUnits.Any(o => organizationUnitIds.Contains(o.OrganizationUnitId)));
            }
            return(query
                   .WhereIf(
                       !input.Filter.IsNullOrWhiteSpace(),
                       u =>
                       u.UserName.Contains(input.Filter) ||
                       u.Email.Contains(input.Filter) ||
                       (u.Name != null && u.Name.Contains(input.Filter)) ||
                       (u.Surname != null && u.Surname.Contains(input.Filter)) ||
                       (u.PhoneNumber != null && u.PhoneNumber.Contains(input.Filter))
                       )
                   .WhereIf(input.RoleId != null, u => u.Roles.Any(x => x.RoleId == input.RoleId))
                   //.WhereIf(input.OrganizationUnitId != null, u => u.OrganizationUnits.Any(x => x.OrganizationUnitId == input.OrganizationUnitId))
                   );
        }