This commit is contained in:
@@ -72,9 +72,9 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: GET BY RELATIVE
|
//TODO: GET BY RELATIVE
|
||||||
//get by descendent type and id
|
//get by descendent type and id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -120,18 +120,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: this should post a workorder instead, no need for Create first like this
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Post WorkOrder
|
/// Post Workorder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="workorderTemplateId"></param>
|
/// <param name="inObj"></param>
|
||||||
/// <param name="customerId"></param>
|
|
||||||
/// <param name="serial">force a workorder number, leave null to autogenerate the next one in sequence (mostly used for import)</param>
|
|
||||||
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
/// <returns>A created workorder ready to fill out</returns>
|
/// <returns></returns>
|
||||||
[HttpPost("Create")]
|
[HttpPost]
|
||||||
public async Task<IActionResult> PostWorkOrder([FromQuery] long? workorderTemplateId, long? customerId, uint? serial, ApiVersion apiVersion)
|
public async Task<IActionResult> PostWorkOrder([FromBody] WorkOrder inObj, 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));
|
||||||
@@ -147,13 +143,47 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
//Create and validate
|
//Create and validate
|
||||||
WorkOrder o = await biz.CreateAsync(workorderTemplateId,customerId, serial);
|
WorkOrder o = await biz.CreateAsync(inObj);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
else
|
||||||
return CreatedAtAction(nameof(WorkOrderController.GetWorkOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
return CreatedAtAction(nameof(WorkOrderController.GetWorkOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /// <summary>
|
||||||
|
// /// Post WorkOrder
|
||||||
|
// /// </summary>
|
||||||
|
// /// <param name="workorderTemplateId"></param>
|
||||||
|
// /// <param name="customerId"></param>
|
||||||
|
// /// <param name="serial">force a workorder number, leave null to autogenerate the next one in sequence (mostly used for import)</param>
|
||||||
|
// /// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
|
// /// <returns>A created workorder ready to fill out</returns>
|
||||||
|
// [HttpPost("Create")]
|
||||||
|
// public async Task<IActionResult> PostWorkOrder([FromQuery] long? workorderTemplateId, long? customerId, uint? serial, ApiVersion apiVersion)
|
||||||
|
// {
|
||||||
|
// 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
|
||||||
|
// WorkOrder o = await biz.CreateAsync(workorderTemplateId,customerId, serial);
|
||||||
|
// 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));
|
||||||
|
// }
|
||||||
|
|
||||||
//TODO: CreateFromTemplate(templateid)
|
//TODO: CreateFromTemplate(templateid)
|
||||||
//TODO: Createfromquote(quoteid)
|
//TODO: Createfromquote(quoteid)
|
||||||
//todo: createfrompm(pmid)
|
//todo: createfrompm(pmid)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ WARNING: Since version 3.0.0, each Include will cause an additional JOIN to be a
|
|||||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
||||||
//var ret = await ct.WorkOrder.SingleOrDefaultAsync(m => m.Id == fetchId);
|
//var ret = await ct.WorkOrder.SingleOrDefaultAsync(m => m.Id == fetchId);
|
||||||
|
|
||||||
var ret = await ct.WorkOrder.Include(w=>w.WorkorderItems).SingleOrDefaultAsync(m => m.Id == fetchId);
|
var ret = await ct.WorkOrder.Include(w => w.WorkorderItems).SingleOrDefaultAsync(m => m.Id == fetchId);
|
||||||
|
|
||||||
if (logTheGetEvent && ret != null)
|
if (logTheGetEvent && ret != null)
|
||||||
{
|
{
|
||||||
@@ -78,45 +78,74 @@ WARNING: Since version 3.0.0, each Include will cause an additional JOIN to be a
|
|||||||
|
|
||||||
//TODO: Modify this to expect a workorder object like most POST routes for other objects
|
//TODO: Modify this to expect a workorder object like most POST routes for other objects
|
||||||
//No need for this style of create empty and return
|
//No need for this style of create empty and return
|
||||||
|
|
||||||
|
|
||||||
//Called from route and also seeder
|
//Called from route and also seeder
|
||||||
internal async Task<WorkOrder> CreateAsync(long? workorderTemplateId, long? customerId, uint? serial)
|
internal async Task<WorkOrder> CreateAsync(WorkOrder inObj)
|
||||||
{
|
{
|
||||||
//Create and save to db a new workorder and return it
|
await ValidateAsync(inObj, null);
|
||||||
//NOTE: Serial can be specified or edited after the fact in a limited way by full role specfic only!! (service manager, bizadminfull, accounting maybe)
|
if (HasErrors)
|
||||||
|
|
||||||
if (serial != null && !Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
|
||||||
{
|
|
||||||
AddError(ApiErrorCode.NOT_AUTHORIZED, "Serial");
|
|
||||||
return null;
|
return null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//do stuff with widget
|
||||||
|
WorkOrder outObj = inObj;
|
||||||
|
|
||||||
|
//Test get serial id visible id number from generator
|
||||||
|
outObj.Serial = ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||||
|
|
||||||
|
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
||||||
|
outObj.CustomFields = JsonUtil.CompactJson(outObj.CustomFields);
|
||||||
|
//Save to db
|
||||||
|
await ct.WorkOrder.AddAsync(outObj);
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
//Handle child and associated items:
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||||
|
await SearchIndexAsync(outObj, true);
|
||||||
|
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
||||||
|
|
||||||
|
return outObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// await ValidateAsync(inObj, null);
|
|
||||||
// if (HasErrors)
|
|
||||||
// return null;
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
//do stuff with WorkOrder
|
|
||||||
WorkOrder o = new WorkOrder();
|
|
||||||
o.Serial = serial ?? ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
|
||||||
|
|
||||||
//TODO: template
|
|
||||||
//TODO: CUSTOMER ID
|
|
||||||
|
|
||||||
|
|
||||||
//Save to db
|
|
||||||
await ct.WorkOrder.AddAsync(o);
|
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
//Handle child and associated items:
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, o.Id, BizType, AyaEvent.Created), ct);
|
|
||||||
await SearchIndexAsync(o, true);
|
|
||||||
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, o.Tags, null);
|
|
||||||
|
|
||||||
return o;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// //Called from route and also seeder
|
||||||
|
// internal async Task<WorkOrder> CreateAsync(long? workorderTemplateId, long? customerId, uint? serial)
|
||||||
|
// {
|
||||||
|
// //Create and save to db a new workorder and return it
|
||||||
|
// //NOTE: Serial can be specified or edited after the fact in a limited way by full role specfic only!! (service manager, bizadminfull, accounting maybe)
|
||||||
|
|
||||||
|
// if (serial != null && !Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
||||||
|
// {
|
||||||
|
// AddError(ApiErrorCode.NOT_AUTHORIZED, "Serial");
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// // await ValidateAsync(inObj, null);
|
||||||
|
// // if (HasErrors)
|
||||||
|
// // return null;
|
||||||
|
// // else
|
||||||
|
// // {
|
||||||
|
// //do stuff with WorkOrder
|
||||||
|
// WorkOrder o = new WorkOrder();
|
||||||
|
// o.Serial = serial ?? ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||||
|
|
||||||
|
// //TODO: template
|
||||||
|
// //TODO: CUSTOMER ID
|
||||||
|
|
||||||
|
|
||||||
|
// //Save to db
|
||||||
|
// await ct.WorkOrder.AddAsync(o);
|
||||||
|
// await ct.SaveChangesAsync();
|
||||||
|
// //Handle child and associated items:
|
||||||
|
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, o.Id, BizType, AyaEvent.Created), ct);
|
||||||
|
// await SearchIndexAsync(o, true);
|
||||||
|
// // await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, o.Tags, null);
|
||||||
|
|
||||||
|
// return o;
|
||||||
|
// //}
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user