@@ -8,7 +8,6 @@ namespace Microsoft.SCIM.WebHostSample.Provider
8
8
using System . Linq . Expressions ;
9
9
using System . Net ;
10
10
using System . Threading . Tasks ;
11
- using System . Web . Http ;
12
11
using Microsoft . SCIM ;
13
12
14
13
public class InMemoryGroupProvider : ProviderBase
@@ -20,18 +19,18 @@ public InMemoryGroupProvider()
20
19
this . storage = InMemoryStorage . Instance ;
21
20
}
22
21
23
- public override Task < Resource > CreateAsync ( Resource resource , string correlationIdentifier )
22
+ public override Task < Resource > CreateAsync ( Resource resource , string correlationIdentifier )
24
23
{
25
24
if ( resource . Identifier != null )
26
25
{
27
- throw new HttpResponseException ( HttpStatusCode . BadRequest ) ;
26
+ throw new CustomHttpResponseException ( HttpStatusCode . BadRequest ) ;
28
27
}
29
28
30
29
Core2Group group = resource as Core2Group ;
31
30
32
31
if ( string . IsNullOrWhiteSpace ( group . DisplayName ) )
33
32
{
34
- throw new HttpResponseException ( HttpStatusCode . BadRequest ) ;
33
+ throw new CustomHttpResponseException ( HttpStatusCode . BadRequest ) ;
35
34
}
36
35
37
36
IEnumerable < Core2Group > exisitingGroups = this . storage . Groups . Values ;
@@ -42,7 +41,7 @@ public override Task<Resource> CreateAsync(Resource resource, string correlation
42
41
string . Equals ( exisitingGroup . DisplayName , group . DisplayName , StringComparison . Ordinal ) )
43
42
)
44
43
{
45
- throw new HttpResponseException ( HttpStatusCode . Conflict ) ;
44
+ throw new CustomHttpResponseException ( HttpStatusCode . Conflict ) ;
46
45
}
47
46
//Update Metadata
48
47
DateTime created = DateTime . UtcNow ;
@@ -56,21 +55,23 @@ public override Task<Resource> CreateAsync(Resource resource, string correlation
56
55
return Task . FromResult ( resource ) ;
57
56
}
58
57
59
- public override Task DeleteAsync ( IResourceIdentifier resourceIdentifier , string correlationIdentifier )
58
+ public override Task < Resource > DeleteAsync ( IResourceIdentifier resourceIdentifier ,
59
+ string correlationIdentifier )
60
60
{
61
61
if ( string . IsNullOrWhiteSpace ( resourceIdentifier ? . Identifier ) )
62
62
{
63
- throw new HttpResponseException ( HttpStatusCode . BadRequest ) ;
63
+ throw new CustomHttpResponseException ( HttpStatusCode . BadRequest ) ;
64
64
}
65
65
66
66
string identifier = resourceIdentifier . Identifier ;
67
67
68
68
if ( this . storage . Groups . ContainsKey ( identifier ) )
69
69
{
70
+ var group = this . storage . Groups [ identifier ] ;
70
71
this . storage . Groups . Remove ( identifier ) ;
72
+ return Task . FromResult ( group as Resource ) ;
71
73
}
72
-
73
- return Task . CompletedTask ;
74
+ throw new CustomHttpResponseException ( HttpStatusCode . NotFound ) ;
74
75
}
75
76
76
77
public override Task < Resource [ ] > QueryAsync ( IQueryParameters parameters , string correlationIdentifier )
@@ -127,17 +128,17 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
127
128
128
129
if ( queryFilter . AttributePath . Equals ( AttributeNames . DisplayName ) )
129
130
{
130
-
131
+
131
132
string displayName = queryFilter . ComparisonValue ;
132
133
predicateAnd = predicateAnd . And ( p => string . Equals ( p . DisplayName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
133
-
134
+
134
135
}
135
136
else
136
137
{
137
138
throw new NotSupportedException ( string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterAttributePathNotSupportedTemplate , queryFilter . AttributePath ) ) ;
138
139
}
139
140
}
140
-
141
+
141
142
predicate = predicate . Or ( predicateAnd ) ;
142
143
results = this . storage . Groups . Values . Where ( predicate . Compile ( ) ) ;
143
144
@@ -148,14 +149,14 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
148
149
{
149
150
if ( resource . Identifier == null )
150
151
{
151
- throw new HttpResponseException ( HttpStatusCode . BadRequest ) ;
152
+ throw new CustomHttpResponseException ( HttpStatusCode . BadRequest ) ;
152
153
}
153
154
154
155
Core2Group group = resource as Core2Group ;
155
156
156
157
if ( string . IsNullOrWhiteSpace ( group . DisplayName ) )
157
158
{
158
- throw new HttpResponseException ( HttpStatusCode . BadRequest ) ;
159
+ throw new CustomHttpResponseException ( HttpStatusCode . BadRequest ) ;
159
160
}
160
161
161
162
Core2Group exisitingGroups = resource as Core2Group ;
@@ -167,12 +168,12 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
167
168
! string . Equals ( exisitingUser . Identifier , group . Identifier , StringComparison . OrdinalIgnoreCase ) )
168
169
)
169
170
{
170
- throw new HttpResponseException ( HttpStatusCode . Conflict ) ;
171
+ throw new CustomHttpResponseException ( HttpStatusCode . Conflict ) ;
171
172
}
172
173
173
174
if ( ! this . storage . Groups . TryGetValue ( group . Identifier , out Core2Group _ ) )
174
175
{
175
- throw new HttpResponseException ( HttpStatusCode . NotFound ) ;
176
+ throw new CustomHttpResponseException ( HttpStatusCode . NotFound ) ;
176
177
}
177
178
178
179
// Update metadata
@@ -211,11 +212,10 @@ public override Task<Resource> RetrieveAsync(IResourceRetrievalParameters parame
211
212
return Task . FromResult ( result ) ;
212
213
}
213
214
}
214
-
215
- throw new HttpResponseException ( HttpStatusCode . NotFound ) ;
215
+ throw new CustomHttpResponseException ( HttpStatusCode . NotFound ) ;
216
216
}
217
217
218
- public override Task UpdateAsync ( IPatch patch , string correlationIdentifier )
218
+ public override Task < Resource > UpdateAsync ( IPatch patch , string correlationIdentifier )
219
219
{
220
220
if ( null == patch )
221
221
{
@@ -254,10 +254,10 @@ public override Task UpdateAsync(IPatch patch, string correlationIdentifier)
254
254
}
255
255
else
256
256
{
257
- throw new HttpResponseException ( HttpStatusCode . NotFound ) ;
257
+ throw new CustomHttpResponseException ( HttpStatusCode . NotFound ) ;
258
258
}
259
259
260
- return Task . CompletedTask ;
260
+ return Task . FromResult ( group as Resource ) ;
261
261
}
262
262
}
263
263
}
0 commit comments