This commit is contained in:
@@ -141,7 +141,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
case AyaType.WorkOrderItemTravel:
|
case AyaType.WorkOrderItemTravel:
|
||||||
case AyaType.WorkOrderItemOutsideService:
|
case AyaType.WorkOrderItemOutsideService:
|
||||||
case AyaType.WorkOrderItemUnit:
|
case AyaType.WorkOrderItemUnit:
|
||||||
AyaTypeId TypeId = await WorkOrderBiz.GetAncestor(ayaType, id, ct);
|
AyaTypeId TypeId = new AyaTypeId(AyaType.WorkOrder, await WorkOrderBiz.GetWorkOrderIdFromDescendant(ayaType, id, ct));
|
||||||
return Ok(ApiOkResponse.Response(new { AyaType = TypeId.ATypeAsInt, Id = TypeId.ObjectId }));
|
return Ok(ApiOkResponse.Response(new { AyaType = TypeId.ATypeAsInt, Id = TypeId.ObjectId }));
|
||||||
default:
|
default:
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Only types with ancestors are valid"));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Only types with ancestors are valid"));
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WorkOrder dbObject = await ct.WorkOrder.SingleOrDefaultAsync(z => z.Id == id);
|
WorkOrder dbObject = await WorkOrderGetAsync(id,false);
|
||||||
if (dbObject == null)
|
if (dbObject == null)
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
@@ -232,6 +232,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
//NOTE: no need to rollback the transaction, it will auto-rollback if not committed and it is disposed when it goes out of scope either way
|
||||||
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||||
throw;
|
throw;
|
||||||
|
|
||||||
@@ -245,9 +246,9 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//GET ANCESTOR TYPE AND ID
|
//GET WORKORDER ID FROM DESCENDANT TYPE AND ID
|
||||||
//
|
//
|
||||||
internal static async Task<AyaTypeId> GetAncestor(AyaType ayaType, long id, AyContext ct)
|
internal static async Task<long> GetWorkOrderIdFromDescendant(AyaType ayaType, long id, AyContext ct)
|
||||||
{
|
{
|
||||||
long woitemid = 0;
|
long woitemid = 0;
|
||||||
switch (ayaType)
|
switch (ayaType)
|
||||||
@@ -288,7 +289,10 @@ namespace AyaNova.Biz
|
|||||||
default:
|
default:
|
||||||
throw new System.NotSupportedException($"WorkOrderBiz::GetAncestor -> AyaType {ayaType.ToString()} is not supported");
|
throw new System.NotSupportedException($"WorkOrderBiz::GetAncestor -> AyaType {ayaType.ToString()} is not supported");
|
||||||
}
|
}
|
||||||
return new AyaTypeId(AyaType.WorkOrder, await ct.WorkOrderItem.Where(z => z.Id == woitemid).Select(z => z.WorkOrderId).SingleOrDefaultAsync());
|
return await ct.WorkOrderItem.AsNoTracking()
|
||||||
|
.Where(z => z.Id == woitemid)
|
||||||
|
.Select(z => z.WorkOrderId)
|
||||||
|
.SingleOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user