1
- using System ;
2
- using System . Reflection ;
3
1
using System . Threading . Tasks ;
4
2
using JsonApiDotNetCore . Configuration ;
5
3
using JsonApiDotNetCore . Extensions ;
@@ -106,7 +104,11 @@ public virtual async Task<IActionResult> GetAsync(TId id)
106
104
if ( _getById == null ) throw Exceptions . UnSupportedRequestMethod ;
107
105
var entity = await _getById . GetAsync ( id ) ;
108
106
if ( entity == null )
109
- return NotFound ( ) ;
107
+ {
108
+ // remove the null argument as soon as this has been resolved:
109
+ // https://github.com/aspnet/AspNetCore/issues/16969
110
+ return NotFound ( null ) ;
111
+ }
110
112
111
113
return Ok ( entity ) ;
112
114
}
@@ -117,7 +119,11 @@ public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string re
117
119
throw Exceptions . UnSupportedRequestMethod ;
118
120
var relationship = await _getRelationships . GetRelationshipsAsync ( id , relationshipName ) ;
119
121
if ( relationship == null )
120
- return NotFound ( ) ;
122
+ {
123
+ // remove the null argument as soon as this has been resolved:
124
+ // https://github.com/aspnet/AspNetCore/issues/16969
125
+ return NotFound ( null ) ;
126
+ }
121
127
122
128
return Ok ( relationship ) ;
123
129
}
@@ -141,7 +147,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
141
147
return Forbidden ( ) ;
142
148
143
149
if ( _jsonApiOptions . ValidateModelState && ! ModelState . IsValid )
144
- return UnprocessableEntity ( ModelState . ConvertToErrorCollection < T > ( GetAssociatedResource ( ) ) ) ;
150
+ return UnprocessableEntity ( ModelState . ConvertToErrorCollection < T > ( ) ) ;
145
151
146
152
entity = await _create . CreateAsync ( entity ) ;
147
153
@@ -155,12 +161,17 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
155
161
return UnprocessableEntity ( ) ;
156
162
157
163
if ( _jsonApiOptions . ValidateModelState && ! ModelState . IsValid )
158
- return UnprocessableEntity ( ModelState . ConvertToErrorCollection < T > ( GetAssociatedResource ( ) ) ) ;
164
+ return UnprocessableEntity ( ModelState . ConvertToErrorCollection < T > ( ) ) ;
159
165
160
166
var updatedEntity = await _update . UpdateAsync ( id , entity ) ;
161
167
162
168
if ( updatedEntity == null )
163
- return NotFound ( ) ;
169
+ {
170
+ // remove the null argument as soon as this has been resolved:
171
+ // https://github.com/aspnet/AspNetCore/issues/16969
172
+ return NotFound ( null ) ;
173
+ }
174
+
164
175
165
176
return Ok ( updatedEntity ) ;
166
177
}
@@ -180,14 +191,8 @@ public virtual async Task<IActionResult> DeleteAsync(TId id)
180
191
return NotFound ( ) ;
181
192
return NoContent ( ) ;
182
193
}
183
-
184
- internal Type GetAssociatedResource ( )
185
- {
186
- return GetType ( ) . GetMethod ( nameof ( GetAssociatedResource ) , BindingFlags . Instance | BindingFlags . NonPublic )
187
- . DeclaringType
188
- . GetGenericArguments ( ) [ 0 ] ;
189
- }
190
194
}
195
+
191
196
public class BaseJsonApiController < T >
192
197
: BaseJsonApiController < T , int >
193
198
where T : class , IIdentifiable < int >
0 commit comments