-
Notifications
You must be signed in to change notification settings - Fork 39
/
EntityWebApiController_cs.hbs
125 lines (117 loc) · 8.05 KB
/
EntityWebApiController_cs.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{{! Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef }}
/*
* This file is automatically generated; any changes will be lost.
*/
{{#if Root.PreprocessorDirectives}}
#nullable enable
#pragma warning disable
{{/if}}
namespace {{Root.NamespaceApi}}.Controllers;
/// <summary>
/// Provides the {{{EntityNameSeeComments}}} Web API functionality.
/// </summary>
{{#ifge WebApiTags.Count 1}}
[Tags({{#each WebApiTags}}"{{.}}"{{#unless @last}}, {{/unless}}{{/each}})]
{{/ifge}}
{{#ifval WebApiAuthorize}}
[{{{WebApiAuthorize}}}]
{{/ifval}}
[Consumes(System.Net.Mime.MediaTypeNames.Application.Json)]
[Produces(System.Net.Mime.MediaTypeNames.Application.Json)]
public partial class {{Name}}Controller : ControllerBase
{
{{#each WebApiCtorParameters}}
private readonly {{Type}} {{PrivateName}};
{{#if @last}}
{{/if}}
{{/each}}
/// <summary>
/// Initializes a new instance of the <see cref="{{Name}}Controller"/> class.
/// </summary>
{{#each WebApiCtorParameters}}
/// <param name="{{ArgumentName}}">{{{SummaryText}}}</param>
{{/each}}
{{lower WebApiCtor}} {{Name}}Controller({{#each WebApiCtorParameters}}{{#unless @first}}, {{/unless}}{{Type}} {{ArgumentName}}{{/each}})
{{#ifle WebApiCtorParameters.Count 5}}
{ {{#each WebApiCtorParameters}}{{PrivateName}} = {{ArgumentName}}.ThrowIfNull(); {{/each}}{{Name}}ControllerCtor(); }
{{else}}
{
{{#each WebApiCtorParameters}}
{{PrivateName}} = {{ArgumentName}}.ThrowIfNull();
{{/each}}
{{Name}}ControllerCtor();
}
{{/ifle}}
partial void {{Name}}ControllerCtor(); // Enables additional functionality to be added to the constructor.
{{#each WebApiOperations}}
{{#unless @first}}
{{/unless}}
/// <summary>
/// {{{sanitize-comments SummaryText}}}
/// </summary>
{{#each CoreParameters}}
{{#ifeq WebApiFrom 'FromEntityProperties'}}
{{#each RelatedEntity.Properties}}
/// <param name="{{ArgumentName}}">{{{sanitize-comments ParameterSummaryText}}}</param>
{{/each}}
{{else}}
/// <param name="{{ArgumentName}}">{{{sanitize-comments SummaryText}}}</param>
{{/ifeq}}
{{/each}}
{{#if HasReturnValue}}
/// <returns>{{{sanitize-comments WebApiReturnText}}}</returns>
{{/if}}
{{#ifge WebApiTags.Count 1}}
[Tags({{#each WebApiTags}}"{{.}}"{{#unless @last}}, {{/unless}}{{/each}})]
{{/ifge}}
{{#ifval WebApiAuthorize}}
[{{{WebApiAuthorize}}}]
{{/ifval}}
[{{WebApiMethod}}("{{WebApiRoute}}", Name="{{Parent.Name}}_{{Name}}")]
{{#if Paging}}
[Paging]
{{/if}}
{{#if Query}}
[Query]
{{/if}}
{{#if HasValue}}
[AcceptsBody(typeof({{CommonValueType}}){{#ifeq WebApiMethod 'HttpPatch'}}, HttpConsts.MergePatchMediaTypeName{{/ifeq}})]
{{/if}}
{{#if WebApiProducesContentType}}
[Produces({{WebApiProducesContentType}})]
{{/if}}
[ProducesResponseType({{#if WebApiProducesResponseType}}{{#if IsWebApiProducesResponseTypeNone}}{{else}}typeof({{WebApiProducesResponseType}}), {{/if}}{{else}}{{#if HasReturnValue}}typeof({{CommonBaseReturnType}}{{#ifeq Type 'GetColl'}}Collection{{/ifeq}}), {{/if}}{{/if}}(int)HttpStatusCode.{{WebApiStatus}})]
{{#ifne WebApiAlternateStatus 'none'}}
[ProducesResponseType((int)HttpStatusCode.{{WebApiAlternateStatus}})]
{{/ifne}}
public Task<IActionResult> {{Name}}({{#each CoreParameters}}{{#unless @first}}, {{/unless}}{{#ifeq WebApiFrom 'FromEntityProperties'}}{{#each RelatedEntity.Properties}}{{#unless @first}}, {{/unless}}{{#ifval JsonName}}[FromQuery(Name="{{JsonName}}")] {{/ifval}}{{{WebApiParameterType}}} {{ArgumentName}} = {{#ifval Default}}{{Default}}{{else}}default{{/ifval}}{{/each}}{{else}}{{#ifne WebApiFrom 'FromQuery'}}[{{WebApiFrom}}] {{/ifne}}{{{WebApiParameterType}}} {{ArgumentName}}{{#ifval Default}} = {{Default}}{{/ifval}}{{/ifeq}}{{/each}})
{{#if HasFromEntityPropertiesParameters}}
{
{{/if}}
{{#each Parameters}}
{{#ifeq WebApiFrom 'FromEntityProperties'}}
var {{ArgumentName}} = new {{Type}} { {{#each RelatedEntity.Properties}}{{#unless @first}}, {{/unless}}{{PropertyName}} = {{ArgumentName}}{{/each}} };
{{/ifeq}}
{{/each}}
{{#ifeq WebApiMethod 'HttpGet'}}
{{#if HasFromEntityPropertiesParameters}}return {{else}}=> {{/if}}_webApi.{{ControllerOperationWebApiMethod}}(Request, p => _manager.{{Name}}Async({{#each Parameters}}{{#unless @first}}, {{/unless}}{{#if IsValueArg}}p.Value!{{else}}{{#if IsQueryArgs}}p.RequestOptions.Query{{else}}{{#if IsPagingArgs}}p.RequestOptions.Paging{{else}}{{ArgumentName}}{{/if}}{{/if}}{{/if}}{{/each}}){{#ifne WebApiStatus 'OK'}}, statusCode: HttpStatusCode.{{WebApiStatus}}{{/ifne}}{{#if HasReturnValue}}{{#ifne WebApiAlternateStatus 'NotFound'}}, alternateStatusCode: HttpStatusCode.{{WebApiAlternateStatus}}{{/ifne}}{{/if}}{{#ifne ManagerOperationType 'Read'}}, operationType: CoreEx.OperationType.{{ManagerOperationType}}{{/ifne}});
{{/ifeq}}
{{#ifeq WebApiMethod 'HttpPost'}}
{{#if HasFromEntityPropertiesParameters}}return {{else}}=> {{/if}}_webApi.{{ControllerOperationWebApiMethod}}(Request, p => _manager.{{Name}}Async({{#each Parameters}}{{#unless @first}}, {{/unless}}{{#if IsValueArg}}p.Value!{{else}}{{#if IsPagingArgs}}p.RequestOptions.Paging{{else}}{{ArgumentName}}{{/if}}{{/if}}{{/each}}){{#ifne WebApiStatus 'OK'}}, statusCode: HttpStatusCode.{{WebApiStatus}}{{/ifne}}{{#if HasReturnValue}}{{#ifne WebApiAlternateStatus 'none'}}, alternateStatusCode: HttpStatusCode.{{WebApiAlternateStatus}}{{/ifne}}{{/if}}{{#ifne ManagerOperationType 'Create'}}, operationType: CoreEx.OperationType.{{ManagerOperationType}}{{/ifne}}{{#ifval WebApiLocation}}, locationUri: {{#if HasReturnValue}}r{{else}}(){{/if}} => new Uri($"{{WebApiLocation}}", UriKind.Relative){{/ifval}});
{{/ifeq}}
{{#ifeq WebApiMethod 'HttpPut'}}
{{#if HasFromEntityPropertiesParameters}}return {{else}}=> {{/if}}_webApi.{{ControllerOperationWebApiMethod}}(Request, {{#if WebApiConcurrency}}get: _ => {{WebApiGetVariable}}.{{WebApiGetOperation}}Async({{#each ValueLessParameters}}{{#unless @first}}, {{/unless}}{{ArgumentName}}{{/each}}), put: {{/if}}p => {{WebApiUpdateVariable}}.{{#if WebApiConcurrency}}{{WebApiUpdateOperation}}{{else}}{{Name}}{{/if}}Async({{#each Parameters}}{{#unless @first}}, {{/unless}}{{#if IsValueArg}}p.Value!{{else}}{{ArgumentName}}{{/if}}{{/each}}){{#ifne WebApiStatus 'OK'}}, statusCode: HttpStatusCode.{{WebApiStatus}}{{/ifne}}{{#if HasReturnValue}}{{/if}}{{#ifne ManagerOperationType 'Update'}}, operationType: CoreEx.OperationType.{{ManagerOperationType}}{{/ifne}}{{#if WebApiConcurrency}}, simulatedConcurrency: {{lower WebApiConcurrency}}{{/if}});
{{/ifeq}}
{{#ifeq WebApiMethod 'HttpPatch'}}
{{#if HasFromEntityPropertiesParameters}}return {{else}}=> {{/if}}_webApi.{{ControllerOperationWebApiMethod}}(Request, get: _ => {{WebApiGetVariable}}.{{WebApiGetOperation}}Async({{#each ValueLessParameters}}{{#unless @first}}, {{/unless}}{{ArgumentName}}{{/each}}), put: p => {{WebApiUpdateVariable}}.{{WebApiUpdateOperation}}Async({{#each Parameters}}{{#unless @first}}, {{/unless}}{{#if IsValueArg}}p.Value!{{else}}{{ArgumentName}}{{/if}}{{/each}}){{#ifne WebApiStatus 'OK'}}, statusCode: HttpStatusCode.{{WebApiStatus}}{{/ifne}}{{#if HasReturnValue}}{{/if}}{{#ifne ManagerOperationType 'Update'}}, operationType: CoreEx.OperationType.{{ManagerOperationType}}{{/ifne}}{{#if WebApiConcurrency}}, simulatedConcurrency: {{lower WebApiConcurrency}}{{/if}});
{{/ifeq}}
{{#ifeq WebApiMethod 'HttpDelete'}}
{{#if HasFromEntityPropertiesParameters}}return {{else}}=> {{/if}}_webApi.{{ControllerOperationWebApiMethod}}(Request, p => _manager.{{Name}}Async({{#each Parameters}}{{#unless @first}}, {{/unless}}{{#if IsValueArg}}p.Value!{{else}}{{#if IsPagingArgs}}p.RequestOptions.Paging{{else}}{{ArgumentName}}{{/if}}{{/if}}{{/each}}){{#ifne WebApiStatus 'NoContent'}}, statusCode: HttpStatusCode.{{WebApiStatus}}{{/ifne}}{{#ifne ManagerOperationType 'Delete'}}, operationType: CoreEx.OperationType.{{ManagerOperationType}}{{/ifne}});
{{/ifeq}}
{{#if HasFromEntityPropertiesParameters}}
}
{{/if}}
{{/each}}
}{{#if Root.PreprocessorDirectives}}
#pragma warning restore
#nullable restore{{/if}}