8
8
using System . Linq ;
9
9
using System . Threading . Tasks ;
10
10
using AgileConfig . Server . Apisite . Models . Mapping ;
11
+ using Microsoft . AspNetCore . Mvc . Infrastructure ;
11
12
12
13
namespace AgileConfig . Server . Apisite . Controllers . api
13
14
{
@@ -57,19 +58,22 @@ public async Task<ActionResult<IEnumerable<ApiAppVM>>> GetAll()
57
58
[ HttpGet ( "{id}" ) ]
58
59
public async Task < ActionResult < ApiAppVM > > GetById ( string id )
59
60
{
60
- var result = ( await _appController . Get ( id ) ) as JsonResult ;
61
- dynamic obj = result . Value ;
61
+ var actionResult = await _appController . Get ( id ) ;
62
+ var status = actionResult as IStatusCodeActionResult ;
62
63
63
- if ( obj . success )
64
+ var result = actionResult as JsonResult ;
65
+ dynamic obj = result ? . Value ;
66
+
67
+ if ( obj ? . success ?? false )
64
68
{
65
69
AppVM appVM = obj . data ;
66
70
return Json ( appVM . ToApiAppVM ( ) ) ;
67
71
}
68
72
69
- Response . StatusCode = 400 ;
73
+ Response . StatusCode = status . StatusCode . Value ;
70
74
return Json ( new
71
75
{
72
- obj . message
76
+ obj ? . message
73
77
} ) ;
74
78
}
75
79
@@ -98,17 +102,17 @@ public async Task<IActionResult> Add([FromBody] ApiAppVM model)
98
102
99
103
var result = ( await _appController . Add ( model . ToAppVM ( ) ) ) as JsonResult ;
100
104
101
- dynamic obj = result . Value ;
105
+ dynamic obj = result ? . Value ;
102
106
103
- if ( obj . success == true )
107
+ if ( obj ? . success == true )
104
108
{
105
109
return Created ( "/api/app/" + obj . data . Id , "" ) ;
106
110
}
107
111
108
112
Response . StatusCode = 400 ;
109
113
return Json ( new
110
114
{
111
- obj . message
115
+ obj ? . message
112
116
} ) ;
113
117
}
114
118
@@ -137,18 +141,20 @@ public async Task<IActionResult> Edit(string id, [FromBody] ApiAppVM model)
137
141
_appController . ControllerContext . HttpContext = HttpContext ;
138
142
139
143
model . Id = id ;
140
- var result = ( await _appController . Edit ( model . ToAppVM ( ) ) ) as JsonResult ;
144
+ var actionResult = await _appController . Edit ( model . ToAppVM ( ) ) ;
145
+ var status = actionResult as IStatusCodeActionResult ;
146
+ var result = actionResult as JsonResult ;
141
147
142
- dynamic obj = result . Value ;
143
- if ( obj . success == true )
148
+ dynamic obj = result ? . Value ;
149
+ if ( obj ? . success ?? false )
144
150
{
145
151
return Ok ( ) ;
146
152
}
147
153
148
- Response . StatusCode = 400 ;
154
+ Response . StatusCode = status . StatusCode . Value ;
149
155
return Json ( new
150
156
{
151
- obj . message
157
+ obj ? . message
152
158
} ) ;
153
159
}
154
160
@@ -164,18 +170,20 @@ public async Task<IActionResult> Delete(string id)
164
170
{
165
171
_appController . ControllerContext . HttpContext = HttpContext ;
166
172
167
- var result = ( await _appController . Delete ( id ) ) as JsonResult ;
173
+ var actionResult = await _appController . Delete ( id ) ;
174
+ var status = actionResult as IStatusCodeActionResult ;
175
+ var result = actionResult as JsonResult ;
168
176
169
- dynamic obj = result . Value ;
170
- if ( obj . success == true )
177
+ dynamic obj = result ? . Value ;
178
+ if ( obj ? . success ?? false )
171
179
{
172
180
return NoContent ( ) ;
173
181
}
174
182
175
- Response . StatusCode = 400 ;
183
+ Response . StatusCode = status . StatusCode . Value ;
176
184
return Json ( new
177
185
{
178
- obj . message
186
+ obj ? . message
179
187
} ) ;
180
188
}
181
189
@@ -192,21 +200,23 @@ public async Task<IActionResult> Publish(string appId, EnvString env)
192
200
{
193
201
_configController . ControllerContext . HttpContext = HttpContext ;
194
202
195
- var result = ( await _configController . Publish ( new PublishLogVM ( )
203
+ var actionResult = await _configController . Publish ( new PublishLogVM ( )
196
204
{
197
205
AppId = appId
198
- } , env ) ) as JsonResult ;
206
+ } , env ) ;
207
+ var status = actionResult as IStatusCodeActionResult ;
208
+ var result = actionResult as JsonResult ;
199
209
200
- dynamic obj = result . Value ;
201
- if ( obj . success == true )
210
+ dynamic obj = result ? . Value ;
211
+ if ( obj ? . success ?? false )
202
212
{
203
213
return Ok ( ) ;
204
214
}
205
215
206
- Response . StatusCode = 400 ;
216
+ Response . StatusCode = status . StatusCode . Value ;
207
217
return Json ( new
208
218
{
209
- obj . message
219
+ obj ? . message
210
220
} ) ;
211
221
}
212
222
@@ -244,18 +254,20 @@ public async Task<IActionResult> Rollback(string historyId, EnvString env)
244
254
{
245
255
_configController . ControllerContext . HttpContext = HttpContext ;
246
256
247
- var result = ( await _configController . Rollback ( historyId , env ) ) as JsonResult ;
257
+ var actionResult = await _configController . Rollback ( historyId , env ) ;
258
+ var status = actionResult as IStatusCodeActionResult ;
259
+ var result = actionResult as JsonResult ;
248
260
249
- dynamic obj = result . Value ;
250
- if ( obj . success == true )
261
+ dynamic obj = result ? . Value ;
262
+ if ( obj ? . success ?? false )
251
263
{
252
264
return Ok ( ) ;
253
265
}
254
266
255
- Response . StatusCode = 400 ;
267
+ Response . StatusCode = status . StatusCode . Value ;
256
268
return Json ( new
257
269
{
258
- obj . message
270
+ obj ? . message
259
271
} ) ;
260
272
}
261
273
0 commit comments