|
|
|
|
@@ -363,19 +363,53 @@ Resource POST GET PUT DELETE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: I can see adding or updating a collection of workorderitems but not deleting an entire collection
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create WorkOrderItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="newObject"></param>
|
|
|
|
|
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/items")]
|
|
|
|
|
public async Task<IActionResult> PostWorkOrderItem([FromBody] WorkOrderItem newObject, ApiVersion apiVersion)
|
|
|
|
|
{
|
|
|
|
|
//NOTE: we don't need the workorder id in the route because the workorder item must contain the workorder id anyway
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!serverState.IsOpen)
|
|
|
|
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
|
|
|
|
|
|
|
|
//Instantiate the business object handler
|
|
|
|
|
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
|
|
|
|
|
|
|
|
|
//If a user has change roles
|
|
|
|
|
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
|
|
|
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
|
|
|
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
return BadRequest(new ApiErrorResponse(ModelState));
|
|
|
|
|
|
|
|
|
|
// //Create and validate
|
|
|
|
|
// WorkOrderItem o = await biz.CreateAsync(newObject);
|
|
|
|
|
// if (o == null)
|
|
|
|
|
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
|
|
|
|
// else
|
|
|
|
|
// return CreatedAtAction(nameof(WorkOrderController.GetWorkOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete WorkOrderItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workOrderId"></param>
|
|
|
|
|
/// <param name="workOrderItemId"></param>
|
|
|
|
|
/// <returns>Ok-no content</returns>
|
|
|
|
|
[HttpDelete("{WorkOrderId}/items/{WorkOrderItemId}")]
|
|
|
|
|
public async Task<IActionResult> DeleteWorkOrderItem([FromRoute] long workOrderId, [FromRoute] long workOrderItemId)
|
|
|
|
|
[HttpDelete("/items/{WorkOrderItemId}")]
|
|
|
|
|
public async Task<IActionResult> DeleteWorkOrderItem([FromRoute] long workOrderItemId)
|
|
|
|
|
{
|
|
|
|
|
//NOTE: we don't need the workorder id in the route because the workorder item must contain the workorder id anyway
|
|
|
|
|
|
|
|
|
|
//WorkOrder/{woid}/WorkorderItems <- all workorderitems, post to add new, put to update all as a collection
|
|
|
|
|
//WorkOrder/{WorkOrderId}/WorkorderItems
|
|
|
|
|
if (!serverState.IsOpen)
|
|
|
|
|
@@ -390,12 +424,17 @@ Resource POST GET PUT DELETE
|
|
|
|
|
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
|
|
|
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
|
|
|
|
|
|
|
|
var o = await biz.GetAsync(workOrderId, false);
|
|
|
|
|
if (o == null)
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
//Make sure the item exists first before getting into it
|
|
|
|
|
if (!o.WorkorderItems.Exists(m => m.Id == workOrderItemId))
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
//*******************************************************************************
|
|
|
|
|
//NOTE: I'm thinking there should be no db access in controller
|
|
|
|
|
//let the biz object return not found if necessary
|
|
|
|
|
//*******************************************************************************
|
|
|
|
|
|
|
|
|
|
// var o = await biz.GetAsync(workOrderId, false);
|
|
|
|
|
// if (o == null)
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
// //Make sure the item exists first before getting into it
|
|
|
|
|
// if (!o.WorkorderItems.Exists(m => m.Id == workOrderItemId))
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -417,12 +456,10 @@ Resource POST GET PUT DELETE
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete WorkOrderItemLabor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workOrderId"></param>
|
|
|
|
|
/// <param name="workOrderItemId"></param>
|
|
|
|
|
/// <param name="workOrderItemLaborId"></param>
|
|
|
|
|
/// <returns>Ok-no content</returns>
|
|
|
|
|
[HttpDelete("{WorkOrderId}/items/{WorkOrderItemId}/labors/{WorkOrderItemLaborId}")]
|
|
|
|
|
public async Task<IActionResult> DeleteWorkOrderItemLabor([FromRoute] long workOrderId, [FromRoute] long workOrderItemId, [FromRoute] long workOrderItemLaborId)
|
|
|
|
|
[HttpDelete("/items/labors/{WorkOrderItemLaborId}")]
|
|
|
|
|
public async Task<IActionResult> DeleteWorkOrderItemLabor([FromRoute] long workOrderItemLaborId)
|
|
|
|
|
{
|
|
|
|
|
if (!serverState.IsOpen)
|
|
|
|
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
|
|
|
@@ -436,19 +473,25 @@ Resource POST GET PUT DELETE
|
|
|
|
|
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
|
|
|
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
|
|
|
|
|
|
|
|
var o = await biz.GetAsync(workOrderId, false);
|
|
|
|
|
if (o == null)
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
//*******************************************************************************
|
|
|
|
|
//NOTE: I'm thinking there should be no db access in controller
|
|
|
|
|
//let the biz object return not found if necessary
|
|
|
|
|
//*******************************************************************************
|
|
|
|
|
|
|
|
|
|
//Get WorkorderItem
|
|
|
|
|
var woitem = o.WorkorderItems.FirstOrDefault(m => m.Id == workOrderItemId);
|
|
|
|
|
if (woitem == null)
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
//Get WorkOrderItemLabor
|
|
|
|
|
var woitemlabor = woitem.WorkorderItemLabors.FirstOrDefault(m => m.Id == workOrderItemLaborId);
|
|
|
|
|
if (woitem == null)
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
// var o = await biz.GetAsync(workOrderId, false);
|
|
|
|
|
// if (o == null)
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
// //Get WorkorderItem
|
|
|
|
|
// var woitem = o.WorkorderItems.FirstOrDefault(m => m.Id == workOrderItemId);
|
|
|
|
|
// if (woitem == null)
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
// //Get WorkOrderItemLabor
|
|
|
|
|
// var woitemlabor = woitem.WorkorderItemLabors.FirstOrDefault(m => m.Id == workOrderItemLaborId);
|
|
|
|
|
// if (woitem == null)
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -467,12 +510,10 @@ Resource POST GET PUT DELETE
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete WorkOrderItemPart
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workOrderId"></param>
|
|
|
|
|
/// <param name="workOrderItemId"></param>
|
|
|
|
|
/// <param name="workOrderItemPartId"></param>
|
|
|
|
|
/// <returns>Ok-no content</returns>
|
|
|
|
|
[HttpDelete("{WorkOrderId}/items/{WorkOrderItemId}/parts/{WorkOrderItemPartId}")]
|
|
|
|
|
public async Task<IActionResult> DeleteWorkOrderItemPart([FromRoute] long workOrderId, [FromRoute] long workOrderItemId, [FromRoute] long workOrderItemPartId)
|
|
|
|
|
[HttpDelete("/items/parts/{WorkOrderItemPartId}")]
|
|
|
|
|
public async Task<IActionResult> DeleteWorkOrderItemPart([FromRoute] long workOrderItemPartId)
|
|
|
|
|
{
|
|
|
|
|
if (!serverState.IsOpen)
|
|
|
|
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
|
|
|
@@ -486,12 +527,18 @@ Resource POST GET PUT DELETE
|
|
|
|
|
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
|
|
|
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
|
|
|
|
|
|
|
|
var o = await biz.GetAsync(workOrderId, false);
|
|
|
|
|
if (o == null)
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
//Make sure the item exists first before getting into it
|
|
|
|
|
if (!o.WorkorderItems.Exists(m => m.Id == workOrderItemId))
|
|
|
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
//*******************************************************************************
|
|
|
|
|
//NOTE: I'm thinking there should be no db access in controller
|
|
|
|
|
//let the biz object return not found if necessary
|
|
|
|
|
//*******************************************************************************
|
|
|
|
|
|
|
|
|
|
// var o = await biz.GetAsync(workOrderId, false);
|
|
|
|
|
// if (o == null)
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
// //Make sure the item exists first before getting into it
|
|
|
|
|
// if (!o.WorkorderItems.Exists(m => m.Id == workOrderItemId))
|
|
|
|
|
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|