This commit is contained in:
@@ -190,22 +190,16 @@ namespace AyaNova.Api.Controllers
|
||||
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.WorkOrderItem))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
//Create and validate
|
||||
WorkOrderItem o = await biz.CreateItemAsync(newObject);
|
||||
if (o == null)
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
else
|
||||
return CreatedAtAction(nameof(WorkOrderController.GetWorkOrderItem), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get WorkOrderItem object
|
||||
/// </summary>
|
||||
@@ -227,62 +221,59 @@ namespace AyaNova.Api.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
// var o = await biz.GetAsync(id);
|
||||
// if (o == null)
|
||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
// // NOTE: HERE would be the second check of biz rules before returning the object
|
||||
// // in cases where there is also a business rule to affect retrieval on top of basic rights
|
||||
|
||||
// return Ok(ApiOkResponse.Response(o, !Authorized.HasModifyRole(HttpContext.Items, biz.BizType)));
|
||||
return StatusCode(501);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Put (update) WorkOrderItem
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="updatedObject"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("items/{WorkOrderItemId}")]
|
||||
public async Task<IActionResult> PutWorkOrderItem([FromRoute] long id, [FromBody] WorkOrderItem updatedObject)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
//Instantiate the business object handler
|
||||
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await biz.GetAsync(id, false);
|
||||
var o = await biz.GetItemAsync(id);
|
||||
if (o == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (!await biz.PutAsync(o, updatedObject))
|
||||
// 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));
|
||||
// }
|
||||
// return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
||||
return StatusCode(501);
|
||||
return Ok(ApiOkResponse.Response(o, !Authorized.HasModifyRole(HttpContext.Items, AyaType.WorkOrderItem)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Put (update) WorkOrderItem
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="updatedObject"></param>
|
||||
// /// <returns></returns>
|
||||
// [HttpPut("items/{WorkOrderItemId}")]
|
||||
// public async Task<IActionResult> PutWorkOrderItem([FromRoute] long id, [FromBody] WorkOrderItem updatedObject)
|
||||
// {
|
||||
// if (!serverState.IsOpen)
|
||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
// if (!ModelState.IsValid)
|
||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
// //Instantiate the business object handler
|
||||
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
// var o = await biz.GetAsync(id, false);
|
||||
// if (o == null)
|
||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
// if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
// // try
|
||||
// // {
|
||||
// // if (!await biz.PutAsync(o, updatedObject))
|
||||
// // 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));
|
||||
// // }
|
||||
// // return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
||||
// return StatusCode(501);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -300,6 +300,27 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GET
|
||||
//
|
||||
internal async Task<WorkOrderItem> GetItemAsync(long id, bool logTheGetEvent = true)
|
||||
{
|
||||
//Note: there could be rules checking here in future, i.e. can only get own workorder or something
|
||||
//if so, then need to implement AddError and in route handle Null return with Error check just like PUT route does now
|
||||
|
||||
//https://docs.microsoft.com/en-us/ef/core/querying/related-data
|
||||
//docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections
|
||||
var ret =
|
||||
await ct.WorkOrderItem
|
||||
.Include(wi => wi.WorkorderItemLabors)
|
||||
.Include(wi => wi.WorkorderItemParts)
|
||||
.SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (logTheGetEvent && ret != null)
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, AyaType.WorkOrderItem, AyaEvent.Retrieved), ct);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
|
||||
Reference in New Issue
Block a user