1
1
using System . Collections . Generic ;
2
2
using System . Threading . Tasks ;
3
+ using JsonApiDotNetCore . Configuration ;
3
4
using JsonApiDotNetCore . Controllers ;
4
5
using JsonApiDotNetCore . Models ;
5
6
using JsonApiDotNetCore . Services ;
@@ -13,26 +14,30 @@ namespace JsonApiDotNetCoreExample.Controllers
13
14
public class TodoItemsCustomController : CustomJsonApiController < TodoItem >
14
15
{
15
16
public TodoItemsCustomController (
17
+ IJsonApiOptions options ,
16
18
IResourceService < TodoItem > resourceService ,
17
19
ILoggerFactory loggerFactory )
18
- : base ( resourceService , loggerFactory )
20
+ : base ( options , resourceService , loggerFactory )
19
21
{ }
20
22
}
21
23
22
24
public class CustomJsonApiController < T >
23
25
: CustomJsonApiController < T , int > where T : class , IIdentifiable < int >
24
26
{
25
27
public CustomJsonApiController (
28
+ IJsonApiOptions options ,
26
29
IResourceService < T , int > resourceService ,
27
30
ILoggerFactory loggerFactory )
28
- : base ( resourceService , loggerFactory )
29
- { }
31
+ : base ( options , resourceService , loggerFactory )
32
+ {
33
+ }
30
34
}
31
35
32
36
public class CustomJsonApiController < T , TId >
33
37
: ControllerBase where T : class , IIdentifiable < TId >
34
38
{
35
39
private readonly ILogger _logger ;
40
+ private readonly IJsonApiOptions _options ;
36
41
private readonly IResourceService < T , TId > _resourceService ;
37
42
38
43
protected IActionResult Forbidden ( )
@@ -41,11 +46,13 @@ protected IActionResult Forbidden()
41
46
}
42
47
43
48
public CustomJsonApiController (
49
+ IJsonApiOptions options ,
44
50
IResourceService < T , TId > resourceService ,
45
51
ILoggerFactory loggerFactory )
46
52
{
53
+ _options = options ;
47
54
_resourceService = resourceService ;
48
- _logger = loggerFactory . CreateLogger < JsonApiDotNetCore . Controllers . JsonApiController < T , TId > > ( ) ;
55
+ _logger = loggerFactory . CreateLogger < JsonApiController < T , TId > > ( ) ;
49
56
}
50
57
51
58
public CustomJsonApiController (
@@ -95,8 +102,8 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
95
102
if ( entity == null )
96
103
return UnprocessableEntity ( ) ;
97
104
98
- // if (!_jsonApiContext.Options .AllowClientGeneratedIds && !string.IsNullOrEmpty(entity.StringId))
99
- // return Forbidden();
105
+ if ( _options . AllowClientGeneratedIds && ! string . IsNullOrEmpty ( entity . StringId ) )
106
+ return Forbidden ( ) ;
100
107
101
108
entity = await _resourceService . CreateAsync ( entity ) ;
102
109
0 commit comments