-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTestcarlotsController.dbl
307 lines (279 loc) · 12.9 KB
/
TestcarlotsController.dbl
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
;;*****************************************************************************
;;
;; Title: TestcarlotsController.dbl
;;
;; Description: OData controller for the TESTCARLOT structure.
;;
;;*****************************************************************************
;; WARNING: GENERATED CODE!
;; This file was generated by CodeGen. Avoid editing the file if possible.
;; Any changes you make will be lost of the file is re-generated.
;;*****************************************************************************
import Microsoft.AspNetCore.Http
import Microsoft.OData
import Microsoft.AspNetCore.JsonPatch
import Microsoft.AspNetCore.Mvc
import Microsoft.AspNetCore.OData.Routing.Controllers
import Microsoft.AspNetCore.OData.Routing.Attributes
import Microsoft.AspNetCore.OData.Query
import Microsoft.AspNetCore.OData.Results
import Microsoft.AspNetCore.OData.Formatter
import Microsoft.EntityFrameworkCore
import Microsoft.EntityFrameworkCore.Infrastructure
import Microsoft.Extensions.Options
import System.Collections.Generic
import System.ComponentModel.DataAnnotations
import System.Net.Mime
import Harmony.Core.EF.Extensions
import Harmony.Core.Interface
import Harmony.OData
import Harmony.AspNetCore
import Newtonsoft.Json
import Services.Models
namespace Services.Controllers
{Produces("application/json")}
;;; <summary>
;;; Test car lot
;;; </summary>
;;; <remarks>
;;; OData endpoints for Test car lot
;;; </remarks>
public partial class TestcarlotsController extends ODataController
;;Services provided via dependency injection
private _DbContext, @Services.Models.DBContext
private _ServiceProvider, @IServiceProvider
private _AppSettings, @IOptions<AppSettings>
;;; <summary>
;;; Constructs a new instance of TestcarlotsController
;;; </summary>
;;; <param name="aDbContext">Database context instance (DI)</param>
;;; <param name="aServiceProvider">Service provider instance (DI)</param>
;;; <param name="aAppSettings">Application settings</param>
public method TestcarlotsController
aDbContext, @Services.Models.DBContext
aServiceProvider, @IServiceProvider
aAppSettings, @IOptions<AppSettings>
proc
this._DbContext = aDbContext
this._ServiceProvider = aServiceProvider
this._AppSettings = aAppSettings
endmethod
{HttpGet("Testcarlots")}
{Produces("application/json")}
{ProducesResponseType(^typeof(IEnumerable<Testcarlot>),StatusCodes.Status200OK)}
{EnableQuery(MaxExpansionDepth=4)}
;;; <summary>
;;; Query the entire collection of records
;;; </summary>
;;; <remarks>
;;;
;;; </remarks>
;;; <returns>Returns an IActionResult indicating the status of the operation and containing any data that was returned.</returns>
;;; <response code="200">OK. The operation completed successfully.</response>
;;; <response code="500">Internal server error. Report the issue to the API maintainer.</response>
public method GetTestcarlots, @IActionResult
proc
mreturn Ok(_DbContext.Testcarlots.AsNoTracking())
endmethod
{HttpGet("Testcarlots(Id={aId})")}
{Produces("application/json")}
{ProducesResponseType(^typeof(Testcarlot),StatusCodes.Status200OK)}
{ProducesResponseType(StatusCodes.Status404NotFound)}
{EnableQuery(MaxExpansionDepth=4)}
;;; <summary>
;;; Query a single record identified by unique primary key
;;; </summary>
;;; <remarks>
;;;
;;; </remarks>
;;; <param name="aId" example="123">Car lot ID</param>
;;; <returns>Returns a SingleResult indicating the status of the operation and containing any data that was returned.</returns>
;;; <response code="200">OK. The operation completed successfully.</response>
;;; <response code="404">Not found. The entity being addressed does not exist.</response>
;;; <response code="500">Internal server error. Report the issue to the API maintainer.</response>
public method GetTestcarlotByPK, @SingleResult<Testcarlot>
required in aId, int
proc
mreturn new SingleResult<Testcarlot>(_DbContext.Testcarlots.AsNoTracking().FindQuery<Testcarlot>(_DbContext, aId))
endmethod
{Consumes(MediaTypeNames.Application.Json)}
{Produces("application/json")}
{ProducesResponseType(^typeof(Testcarlot),StatusCodes.Status200OK)}
{ProducesResponseType(StatusCodes.Status400BadRequest)}
{HttpPost("Testcarlots")}
;;; <summary>
;;; Create a new record (automatically assigned primary key)
;;; </summary>
;;; <remarks>
;;;
;;; </remarks>
;;; <returns>Returns an IActionResult indicating the status of the operation and containing any data that was returned.</returns>
;;; <response code="200">OK. The operation completed successfully.</response>
;;; <response code="400">Bad request. The request was malformed or contained inappropriate content.</response>
;;; <response code="500">Internal server error. Report the issue to the API maintainer.</response>
public method PostTestcarlot, @IActionResult
{FromBody}
required in aTestcarlot, @Testcarlot
proc
;;Remove the primary key fields from ModelState
ModelState.Remove("Id")
;; Validate inbound data
if (!ModelState.IsValid)
mreturn ValidationHelper.ReturnValidationError(ModelState)
;;Get the next available primary key value
disposable data keyFactory = (@IPrimaryKeyFactory)_ServiceProvider.GetService(^typeof(IPrimaryKeyFactory))
KeyFactory.AssignPrimaryKey(aTestcarlot)
;;Add the new testcarlot
try
begin
_DbContext.Testcarlots.Add(aTestcarlot)
_DbContext.SaveChanges(keyFactory)
end
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry
mreturn Created(aTestcarlot)
endmethod
{HttpPut("Testcarlots(Id={aId})")}
{Consumes(MediaTypeNames.Application.Json)}
{Produces("application/json")}
{ProducesResponseType(StatusCodes.Status201Created)}
{ProducesResponseType(StatusCodes.Status400BadRequest)}
{ProducesResponseType(StatusCodes.Status404NotFound)}
;;; <summary>
;;; Update a record if it exists otherwise create a new record (primary key provided by client)
;;; </summary>
;;; <remarks>
;;;
;;; </remarks>
;;; <param name="aId" example="123">Car lot ID</param>
;;; <returns>Returns an IActionResult indicating the status of the operation and containing any data that was returned.</returns>
;;; <response code="201">Created. The entity was created but no data is being returned.</response>
;;; <response code="400">Bad request. The request was malformed or contained inappropriate content.</response>
;;; <response code="500">Internal server error. Report the issue to the API maintainer.</response>
public method PutTestcarlot, @IActionResult
required in aId, int
{FromBody}
required in aTestcarlot, @Testcarlot
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn ValidationHelper.ReturnValidationError(ModelState)
;;Ensure that the key values in the URI win over any data that may be in the model object
aTestcarlot.Id = aId
try
begin
;;Add and commit
data existing = _DbContext.Testcarlots.Find(aId)
if(existing == ^null) then
begin
_DbContext.Testcarlots.Add(aTestcarlot)
_DbContext.SaveChanges()
mreturn Created(aTestcarlot)
end
else
begin
aTestcarlot.CopyTo(existing)
_DbContext.SaveChanges()
mreturn NoContent()
end
end
catch (e, @InvalidOperationException)
begin
mreturn BadRequest(e)
end
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry
endmethod
{HttpPatch("Testcarlots(Id={aId})")}
{Consumes(MediaTypeNames.Application.Json)}
{Produces("application/json")}
{ProducesResponseType(StatusCodes.Status204NoContent)}
{ProducesResponseType(StatusCodes.Status400BadRequest)}
{ProducesResponseType(StatusCodes.Status404NotFound)}
;;; <summary>
;;; Patch (partial update) an existing record
;;; </summary>
;;; <remarks>
;;;
;;; </remarks>
;;; <param name="aId" example="123">Car lot ID</param>
;;; <returns>Returns an IActionResult indicating the status of the operation and containing any data that was returned.</returns>
;;; <response code="204">No content. The operation was successful but no data is being returned.</response>
;;; <response code="400">Bad request. The request was malformed or contained inappropriate content.</response>
;;; <response code="404">Not found. The entity being addressed does not exist.</response>
;;; <response code="500">Internal server error. Report the issue to the API maintainer.</response>
public method PatchTestcarlot, @IActionResult
required in aId, int
{FromBody}
required in aTestcarlot, @JsonPatchDocument<Testcarlot>
proc
;; Validate inbound data
if (!ModelState.IsValid)
mreturn ValidationHelper.ReturnValidationError(ModelState)
;;Patch the existing testcarlot
try
begin
;;Get the testcarlot to be updated
data testcarlotToUpdate = _DbContext.Testcarlots.Find(aId)
data patchError, @JsonPatchError, ^null
;;Did we find it?
if(testcarlotToUpdate == ^null)
mreturn NotFound()
;;Apply the changes to the testcarlot we read
aTestcarlot.ApplyTo(testcarlotToUpdate, lambda(error) { patchError = error })
;;if the patchdoc was bad return the error info
if(patchError != ^null)
mreturn BadRequest(string.Format("Error applying patch document: error message {0}, caused by {1}", patchError.ErrorMessage, JsonConvert.SerializeObject(patchError.Operation)))
;;Update and commit
_DbContext.Testcarlots.Update(testcarlotToUpdate)
_DbContext.SaveChanges()
end
catch (e, @InvalidOperationException)
begin
mreturn BadRequest(e)
end
catch (e, @ValidationException)
begin
ModelState.AddModelError("RelationValidation",e.Message)
mreturn ValidationHelper.ReturnValidationError(ModelState)
end
endtry
mreturn NoContent()
endmethod
{HttpDelete("Testcarlots(Id={aId})")}
{ProducesResponseType(StatusCodes.Status204NoContent)}
{ProducesResponseType(StatusCodes.Status404NotFound)}
;;; <summary>
;;; Delete a record
;;; </summary>
;;; <remarks>
;;;
;;; </remarks>
;;; <param name="aId" example="123">Car lot ID</param>
;;; <returns>Returns an IActionResult indicating the status of the operation and containing any data that was returned.</returns>
;;; <response code="204">No content. The operation was successful but no data is being returned.</response>
;;; <response code="404">Not found. The entity being addressed does not exist.</response>
;;; <response code="500">Internal server error. Report the issue to the API maintainer.</response>
public method DeleteTestcarlot, @IActionResult
required in aId, int
proc
;;Get the testcarlot to be deleted
data testcarlotToRemove = _DbContext.Testcarlots.Find(aId)
;;Did we find it?
if (testcarlotToRemove == ^null)
mreturn NotFound()
;;Delete and commit
_DbContext.Testcarlots.Remove(testcarlotToRemove)
_DbContext.SaveChanges()
mreturn NoContent()
endmethod
endclass
endnamespace