@@ -5,6 +5,7 @@ namespace Microsoft.SCIM.WebHostSample.Provider
5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . Linq ;
8
+ using System . Linq . Expressions ;
8
9
using System . Net ;
9
10
using System . Threading . Tasks ;
10
11
using System . Web . Http ;
@@ -94,7 +95,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
94
95
throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
95
96
}
96
97
97
- IEnumerable < Resource > results = new List < Core2EnterpriseUser > ( ) ;
98
+ IEnumerable < Resource > results ;
99
+ var predicate = PredicateBuilder . False < Core2EnterpriseUser > ( ) ;
100
+ Expression < Func < Core2EnterpriseUser , bool > > predicateAnd ;
101
+
98
102
99
103
if ( parameters . AlternateFilters . Count <= 0 )
100
104
{
@@ -103,11 +107,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
103
107
}
104
108
else
105
109
{
106
- results = new List < Core2EnterpriseUser > ( ) ;
107
110
108
111
foreach ( IFilter queryFilter in parameters . AlternateFilters )
109
112
{
110
- IEnumerable < Core2EnterpriseUser > users = this . storage . Users . Values ;
113
+ predicateAnd = PredicateBuilder . True < Core2EnterpriseUser > ( ) ;
111
114
112
115
IFilter andFilter = queryFilter ;
113
116
IFilter currentFilter = andFilter ;
@@ -132,13 +135,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
132
135
string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterOperatorNotSupportedTemplate , andFilter . FilterOperator ) ) ;
133
136
}
134
137
135
- users =
136
- users . Where (
137
- item =>
138
- string . Equals (
139
- item . UserName ,
140
- andFilter . ComparisonValue ,
141
- StringComparison . OrdinalIgnoreCase ) ) ;
138
+ string userName = andFilter . ComparisonValue ;
139
+ predicateAnd = predicateAnd . And ( p => string . Equals ( p . UserName , userName , StringComparison . OrdinalIgnoreCase ) ) ;
140
+
141
+
142
142
}
143
143
144
144
// ExternalId filter
@@ -150,34 +150,13 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
150
150
string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterOperatorNotSupportedTemplate , andFilter . FilterOperator ) ) ;
151
151
}
152
152
153
- users =
154
- users . Where (
155
- item =>
156
- string . Equals (
157
- item . ExternalIdentifier ,
158
- andFilter . ComparisonValue ,
159
- StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
160
- }
161
-
162
- // Id filter
163
- else if ( andFilter . AttributePath . Equals ( AttributeNames . Identifier , StringComparison . OrdinalIgnoreCase ) )
164
- {
165
- if ( andFilter . FilterOperator != ComparisonOperator . Equals )
166
- {
167
- throw new NotSupportedException (
168
- string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterOperatorNotSupportedTemplate , andFilter . FilterOperator ) ) ;
169
- }
153
+ string externalIdentifier = andFilter . ComparisonValue ;
154
+ predicateAnd = predicateAnd . And ( p => string . Equals ( p . ExternalIdentifier , externalIdentifier , StringComparison . OrdinalIgnoreCase ) ) ;
170
155
171
- users =
172
- users . Where (
173
- item =>
174
- string . Equals (
175
- item . Identifier ,
176
- andFilter . ComparisonValue ,
177
- StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
156
+
178
157
}
179
158
180
- // Active filter
159
+ //Active Filter
181
160
else if ( andFilter . AttributePath . Equals ( AttributeNames . Active , StringComparison . OrdinalIgnoreCase ) )
182
161
{
183
162
if ( andFilter . FilterOperator != ComparisonOperator . Equals )
@@ -186,32 +165,34 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
186
165
string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterOperatorNotSupportedTemplate , andFilter . FilterOperator ) ) ;
187
166
}
188
167
189
- users =
190
- users . Where (
191
- item =>
192
- item . Active == bool . Parse ( andFilter . ComparisonValue ) ) . ToList ( ) ;
168
+ bool active = bool . Parse ( andFilter . ComparisonValue ) ;
169
+ predicateAnd = predicateAnd . And ( p => p . Active == active ) ;
170
+
193
171
}
194
172
195
- // LastModified filter
173
+ //LastModified filter
196
174
else if ( andFilter . AttributePath . Equals ( $ "{ AttributeNames . Metadata } .{ AttributeNames . LastModified } ", StringComparison . OrdinalIgnoreCase ) )
197
175
{
198
176
if ( andFilter . FilterOperator == ComparisonOperator . EqualOrGreaterThan )
199
177
{
200
- users =
201
- users . Where (
202
- item =>
203
- item . Metadata . LastModified >= DateTime . Parse ( andFilter . ComparisonValue ) . ToUniversalTime ( ) ) . ToList ( ) ;
178
+ DateTime comparisonValue = DateTime . Parse ( andFilter . ComparisonValue ) . ToUniversalTime ( ) ;
179
+ predicateAnd = predicateAnd . And ( p => p . Metadata . LastModified >= comparisonValue ) ;
180
+
181
+
204
182
}
205
183
else if ( andFilter . FilterOperator == ComparisonOperator . EqualOrLessThan )
206
184
{
207
- users =
208
- users . Where (
209
- item =>
210
- item . Metadata . LastModified <= DateTime . Parse ( andFilter . ComparisonValue ) . ToUniversalTime ( ) ) . ToList ( ) ;
185
+ DateTime comparisonValue = DateTime . Parse ( andFilter . ComparisonValue ) . ToUniversalTime ( ) ;
186
+ predicateAnd = predicateAnd . And ( p => p . Metadata . LastModified <= comparisonValue ) ;
187
+
188
+
211
189
}
212
190
else
213
191
throw new NotSupportedException (
214
192
string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterOperatorNotSupportedTemplate , andFilter . FilterOperator ) ) ;
193
+
194
+
195
+
215
196
}
216
197
else
217
198
throw new NotSupportedException (
@@ -222,8 +203,11 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
222
203
223
204
} while ( currentFilter . AdditionalFilter != null ) ;
224
205
225
- results = results . Union ( users . Select ( ( Core2EnterpriseUser user ) => user as Resource ) . ToList ( ) ) ;
206
+ predicate = predicate . Or ( predicateAnd ) ;
207
+
226
208
}
209
+
210
+ results = this . storage . Users . Values . Where ( predicate . Compile ( ) ) ;
227
211
}
228
212
229
213
if ( parameters . PaginationParameters != null )
0 commit comments