@@ -37,7 +37,7 @@ public static async Task<Results<BadRequest<string>, Ok<AllUsersResponse>>> GetA
3737 if ( ! string . IsNullOrEmpty ( searchQuery . SearchQuery ) )
3838 {
3939 var splitQuery = searchQuery . SearchQuery . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries ) ;
40-
40+
4141 baseQuery = baseQuery . Where ( x =>
4242 splitQuery . Any ( word =>
4343 x . GivenName . ToLower ( ) . Contains ( word . ToLower ( ) ) ||
@@ -73,129 +73,135 @@ public static async Task<Results<BadRequest<string>, Ok<AllUsersResponse>>> GetA
7373 baseQuery = baseQuery . Where ( u =>
7474 db . Set < UserRole > ( ) . Any ( ur => ur . UserId == u . Id && roleIds . Contains ( ur . RoleId ) ) ) ;
7575 }
76+
77+ // ✅ Filter by selected review body user ids
78+ if ( searchQuery ? . UserIds is { Count : > 0 } )
79+ {
80+ baseQuery = baseQuery . Where ( u => searchQuery . UserIds . Contains ( u . Id ) ) ;
81+ }
7682 }
7783
78- // Apply sorting
79- baseQuery = ApplyOrdering ( baseQuery , sortField , sortDirection ) ;
84+ // Apply sorting
85+ baseQuery = ApplyOrdering ( baseQuery , sortField , sortDirection ) ;
8086
81- // Materialize result (EF-safe filters only so far)
82- var usersList = await baseQuery . ToListAsync ( ) ;
87+ // Materialize result (EF-safe filters only so far)
88+ var usersList = await baseQuery . ToListAsync ( ) ;
8389
84- // ✅ Now filter by Country in memory
85- if ( searchQuery ? . Country is { Count : > 0 } )
86- {
87- var lowerCountries = searchQuery . Country
88- . Where ( c => ! string . IsNullOrWhiteSpace ( c ) )
89- . Select ( c => c . ToLowerInvariant ( ) )
90- . ToList ( ) ;
90+ // ✅ Now filter by Country in memory
91+ if ( searchQuery ? . Country is { Count : > 0 } )
92+ {
93+ var lowerCountries = searchQuery . Country
94+ . Where ( c => ! string . IsNullOrWhiteSpace ( c ) )
95+ . Select ( c => c . ToLowerInvariant ( ) )
96+ . ToList ( ) ;
9197
92- usersList = usersList
93- . Where ( x =>
94- ! string . IsNullOrWhiteSpace ( x . Country ) &&
95- x . Country
96- . Split ( ',' , StringSplitOptions . RemoveEmptyEntries )
97- . Select ( c => c . Trim ( ) . ToLowerInvariant ( ) )
98- . Intersect ( lowerCountries )
99- . Any ( ) )
100- . ToList ( ) ;
101- }
98+ usersList = usersList
99+ . Where ( x =>
100+ ! string . IsNullOrWhiteSpace ( x . Country ) &&
101+ x . Country
102+ . Split ( ',' , StringSplitOptions . RemoveEmptyEntries )
103+ . Select ( c => c . Trim ( ) . ToLowerInvariant ( ) )
104+ . Intersect ( lowerCountries )
105+ . Any ( ) )
106+ . ToList ( ) ;
107+ }
102108
103- // ✅ Now paginate in memory after full filtering
104- var usersCount = usersList . Count ;
109+ // ✅ Now paginate in memory after full filtering
110+ var usersCount = usersList . Count ;
105111
106- var users = usersList
107- . Skip ( ( pageIndex - 1 ) * pageSize )
108- . Take ( pageSize )
109- . ToList ( ) ;
112+ var users = usersList
113+ . Skip ( ( pageIndex - 1 ) * pageSize )
114+ . Take ( pageSize )
115+ . ToList ( ) ;
110116
111- return TypedResults . Ok
112- (
113- new AllUsersResponse
114- {
115- Users = users . Select
117+ return TypedResults . Ok
118+ (
119+ new AllUsersResponse
120+ {
121+ Users = users . Select
116122 (
117123 user => new UserDto
118- (
119- user . Id ,
120- user . GivenName ,
121- user . FamilyName ,
122- user . Email ! ,
123- user . Title ,
124- user . JobTitle ,
125- user . Organisation ,
126- user . Telephone ,
127- user . Country ,
128- user . Status ,
129- user . LastLogin ,
130- user . CurrentLogin ,
131- user . LastUpdated
132- )
133- ) ,
134- TotalCount = usersCount
135- }
136- ) ;
137- }
124+ (
125+ user . Id ,
126+ user . GivenName ,
127+ user . FamilyName ,
128+ user . Email ! ,
129+ user . Title ,
130+ user . JobTitle ,
131+ user . Organisation ,
132+ user . Telephone ,
133+ user . Country ,
134+ user . Status ,
135+ user . LastLogin ,
136+ user . CurrentLogin ,
137+ user . LastUpdated
138+ )
139+ ) ,
140+ TotalCount = usersCount
141+ }
142+ ) ;
143+ }
138144
139145 /// <summary>
140- /// Dynamically applies ordering to a queryable based on field and direction.
141- /// </summary>
146+ /// Dynamically applies ordering to a queryable based on field and direction.
147+ /// </summary>
142148 private static IQueryable < TUser > ApplyOrdering < TUser > ( IQueryable < TUser > query , string sortField , string sortDirection ) where TUser : IrasUser
143- {
144- var field = sortField . ToLowerInvariant ( ) ;
145-
146- return ( field , sortDirection ) switch
147149 {
148- ( "givenname" , SortDirections . Ascending ) => query
149- . OrderBy ( x => x . GivenName )
150- . ThenByDescending ( x => x . CurrentLogin )
151- . ThenBy ( x => x . Status ) ,
152-
153- ( "givenname" , SortDirections . Descending ) => query
154- . OrderByDescending ( x => x . GivenName )
155- . ThenByDescending ( x => x . CurrentLogin )
156- . ThenBy ( x => x . Status ) ,
157-
158- ( "familyname" , SortDirections . Ascending ) => query
159- . OrderBy ( x => x . FamilyName )
160- . ThenByDescending ( x => x . CurrentLogin )
161- . ThenBy ( x => x . Status ) ,
162-
163- ( "familyname" , SortDirections . Descending ) => query
164- . OrderByDescending ( x => x . FamilyName )
165- . ThenByDescending ( x => x . CurrentLogin )
166- . ThenBy ( x => x . Status ) ,
167-
168- ( "email" , SortDirections . Ascending ) => query
169- . OrderBy ( x => x . Email )
170- . ThenByDescending ( x => x . CurrentLogin )
171- . ThenBy ( x => x . Status ) ,
172-
173- ( "email" , SortDirections . Descending ) => query
174- . OrderByDescending ( x => x . Email )
175- . ThenByDescending ( x => x . CurrentLogin )
176- . ThenBy ( x => x . Status ) ,
177-
178- ( "status" , SortDirections . Ascending ) => query
179- . OrderBy ( x => x . Status )
180- . ThenByDescending ( x => x . CurrentLogin ) ,
181-
182- ( "status" , SortDirections . Descending ) => query
183- . OrderByDescending ( x => x . Status )
184- . ThenByDescending ( x => x . CurrentLogin )
185- . ThenBy ( x => x . Status ) ,
186-
187- ( "currentlogin" , SortDirections . Ascending ) => query
188- . OrderBy ( x => x . CurrentLogin )
189- . ThenBy ( x => x . Status ) ,
190-
191- ( "currentlogin" , SortDirections . Descending ) => query
192- . OrderByDescending ( x => x . CurrentLogin )
193- . ThenBy ( x => x . Status ) ,
194-
195- _ => query
196- . OrderBy ( x => x . GivenName )
197- . ThenByDescending ( x => x . CurrentLogin )
198- . ThenBy ( x => x . Status )
199- } ;
200- }
201- }
150+ var field = sortField . ToLowerInvariant ( ) ;
151+
152+ return ( field , sortDirection ) switch
153+ {
154+ ( "givenname" , SortDirections . Ascending ) => query
155+ . OrderBy ( x => x . GivenName )
156+ . ThenByDescending ( x => x . CurrentLogin )
157+ . ThenBy ( x => x . Status ) ,
158+
159+ ( "givenname" , SortDirections . Descending ) => query
160+ . OrderByDescending ( x => x . GivenName )
161+ . ThenByDescending ( x => x . CurrentLogin )
162+ . ThenBy ( x => x . Status ) ,
163+
164+ ( "familyname" , SortDirections . Ascending ) => query
165+ . OrderBy ( x => x . FamilyName )
166+ . ThenByDescending ( x => x . CurrentLogin )
167+ . ThenBy ( x => x . Status ) ,
168+
169+ ( "familyname" , SortDirections . Descending ) => query
170+ . OrderByDescending ( x => x . FamilyName )
171+ . ThenByDescending ( x => x . CurrentLogin )
172+ . ThenBy ( x => x . Status ) ,
173+
174+ ( "email" , SortDirections . Ascending ) => query
175+ . OrderBy ( x => x . Email )
176+ . ThenByDescending ( x => x . CurrentLogin )
177+ . ThenBy ( x => x . Status ) ,
178+
179+ ( "email" , SortDirections . Descending ) => query
180+ . OrderByDescending ( x => x . Email )
181+ . ThenByDescending ( x => x . CurrentLogin )
182+ . ThenBy ( x => x . Status ) ,
183+
184+ ( "status" , SortDirections . Ascending ) => query
185+ . OrderBy ( x => x . Status )
186+ . ThenByDescending ( x => x . CurrentLogin ) ,
187+
188+ ( "status" , SortDirections . Descending ) => query
189+ . OrderByDescending ( x => x . Status )
190+ . ThenByDescending ( x => x . CurrentLogin )
191+ . ThenBy ( x => x . Status ) ,
192+
193+ ( "currentlogin" , SortDirections . Ascending ) => query
194+ . OrderBy ( x => x . CurrentLogin )
195+ . ThenBy ( x => x . Status ) ,
196+
197+ ( "currentlogin" , SortDirections . Descending ) => query
198+ . OrderByDescending ( x => x . CurrentLogin )
199+ . ThenBy ( x => x . Status ) ,
200+
201+ _ => query
202+ . OrderBy ( x => x . GivenName )
203+ . ThenByDescending ( x => x . CurrentLogin )
204+ . ThenBy ( x => x . Status )
205+ } ;
206+ }
207+ }
0 commit comments