This commit is contained in:
@@ -176,11 +176,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// Change existing work order's Contract
|
/// Change existing work order's Contract
|
||||||
/// applies new Contract and returns complete updated work order
|
/// applies new Contract and returns complete updated work order
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="workOrderId">Work order id</param>
|
||||||
/// <param name="newContractId">new contract id</param>
|
/// <param name="newContractId">new contract id</param>
|
||||||
/// <param name="apiVersion">From route path</param>
|
/// <param name="apiVersion">From route path</param>
|
||||||
/// <returns>WorkOrder</returns>
|
/// <returns>WorkOrder</returns>
|
||||||
[HttpPost("contract")]
|
[HttpPost("contract/{workOrderId}")]
|
||||||
public async Task<IActionResult> ChangeContract([FromBody] long? newContractId, ApiVersion apiVersion)
|
public async Task<IActionResult> ChangeContract([FromRoute] long workOrderId, [FromBody] long? newContractId, ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
@@ -189,7 +190,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
WorkOrder o = await biz.ChangeContract(newContractId);
|
WorkOrder o = await biz.ChangeContract(workOrderId, newContractId);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -314,7 +314,31 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//CONTRACT UPDATE
|
||||||
|
//
|
||||||
|
internal async Task<WorkOrder> ChangeContract(long workOrderId, long? newContractId)
|
||||||
|
{
|
||||||
|
//this is called by UI via contract change route for contract change only and expects wo back to update client ui
|
||||||
|
var w=await WorkOrderGetAsync(workOrderId,false,false);
|
||||||
|
|
||||||
|
if (w==null)
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(newContractId!=null && !await ct.Contract.AnyAsync(z=>z.Id==newContractId)){
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND,"generalerror", $"Contract with id {newContractId} not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
w.ContractId=newContractId;
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, workOrderId, BizType, AyaEvent.Modified), ct);
|
||||||
|
await GetCurrentContractFromContractIdAsync(newContractId);
|
||||||
|
var updatedWorkOrder = await ProcessChangeOfContractAsync(workOrderId);
|
||||||
|
await WorkOrderPopulateVizFields(updatedWorkOrder);
|
||||||
|
return updatedWorkOrder;//return entire workorder
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user