This commit is contained in:
2022-01-26 18:31:29 +00:00
parent e798abd2bc
commit 649bff878d
4 changed files with 77 additions and 34 deletions

View File

@@ -142,10 +142,10 @@ namespace AyaNova.Api.Controllers
/// Update FormCustom
/// </summary>
/// <param name="formkey"></param>
/// <param name="inObj"></param>
/// <param name="updatedObject"></param>
/// <returns></returns>
[HttpPut("{formkey}")]
public async Task<IActionResult> PutFormCustom([FromRoute] string formkey, [FromBody] FormCustom inObj)
public async Task<IActionResult> PutFormCustom([FromRoute] string formkey, [FromBody] FormCustom updatedObject)
{
if (!serverState.IsOpen && UserIdFromContext.Id(HttpContext.Items) != 1)//bypass for superuser to fix fundamental problems
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -156,26 +156,36 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext);
var o = await biz.GetAsync(formkey);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// var o = await biz.GetAsync(formkey);
// if (o == null)
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
try
var o = await biz.PutAsync(updatedObject);
if (o == null)
{
if (!await biz.PutAsync(o, inObj))
if (biz.Errors.Exists(z => z.Code == ApiErrorCode.CONCURRENCY_CONFLICT))
return StatusCode(409, new ApiErrorResponse(biz.Errors));
else
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
{
if (!await biz.ExistsAsync(formkey))
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
else
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
}
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency })); ;
// try
// {
// if (!await biz.PutAsync(o, inObj))
// return BadRequest(new ApiErrorResponse(biz.Errors));
// }
// catch (DbUpdateConcurrencyException)
// {
// if (!await biz.ExistsAsync(formkey))
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// else
// return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
// }
// return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
}