This commit is contained in:
2020-05-07 22:32:35 +00:00
parent 80a43b1576
commit 3b40abc20c
2 changed files with 26 additions and 22 deletions

View File

@@ -158,10 +158,13 @@ namespace AyaNova.Api.Controllers
/// <summary>
/// Put (update) WorkOrder
/// This route does not update the entire WorkOrder object graph, only the top level
/// in other words nothing in any descendent child collections such as WorkOrderItems and below.
/// Use the separate routes to update descendents of the WorkOrder
/// </summary>
/// <param name="id"></param>
/// <param name="updatedObject"></param>
/// <returns></returns>
/// <param name="id">WorkOrder id</param>
/// <param name="updatedObject">Workorder top level only, no descendents are evaluated</param>
/// <returns>New concurrency token</returns>
[HttpPut("{id}")]
public async Task<IActionResult> PutWorkOrder([FromRoute] long id, [FromBody] WorkOrder updatedObject)
{
@@ -178,8 +181,13 @@ namespace AyaNova.Api.Controllers
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
biz.PutAsync(id, updatedObject);
//todo: handle concurrency in biz object, what to do?
var o = await biz.PutAsync(id, updatedObject);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
//todo: handle concurrency in biz object, what to do?
// var o = await biz.PutAsync(id, updatedObject);
// try
@@ -285,7 +293,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction(nameof(WorkOrderController.GetWorkOrderItem), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
}

View File

@@ -152,25 +152,21 @@ namespace AyaNova.Biz
if (HasErrors)
return null;
// try
// {
// if (o==null)
// return BadRequest(new ApiErrorResponse(biz.Errors));
// }
// catch (DbUpdateConcurrencyException)
// {
// if (!await biz.ExistsAsync(id))
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// else
// return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
// }
//Log event and save context
try
{
await ct.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!await WorkOrderExistsAsync(id))
AddError(ApiErrorCode.NOT_FOUND);
else
new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT);
return null;
}
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
await SearchIndexAsync(dbObject, false);
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
return dbObject;
}