This commit is contained in:
2021-05-17 22:30:09 +00:00
parent 8354193584
commit c0dad70e6d

View File

@@ -216,6 +216,15 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.CONCURRENCY_CONFLICT); AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
return null; return null;
} }
putObject.Tags = TagBiz.NormalizeTags(putObject.Tags);
putObject.CustomFields = JsonUtil.CompactJson(putObject.CustomFields);
await WorkOrderValidateAsync(putObject, dbObject);
if (HasErrors)
return null;
await WorkOrderBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
bool contractChanged = false; bool contractChanged = false;
long? newContractId = null; long? newContractId = null;
if (putObject.ContractId != dbObject.ContractId)//manual change of contract if (putObject.ContractId != dbObject.ContractId)//manual change of contract
@@ -224,12 +233,6 @@ namespace AyaNova.Biz
newContractId = putObject.ContractId; newContractId = putObject.ContractId;
} }
putObject.Tags = TagBiz.NormalizeTags(putObject.Tags);
putObject.CustomFields = JsonUtil.CompactJson(putObject.CustomFields);
await WorkOrderValidateAsync(putObject, dbObject);
if (HasErrors)
return null;
await WorkOrderBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
ct.Replace(dbObject, putObject); ct.Replace(dbObject, putObject);
try try
{ {
@@ -335,15 +338,18 @@ namespace AyaNova.Biz
if (newObj.CustomerId != oldObj.CustomerId) if (newObj.CustomerId != oldObj.CustomerId)
{ {
await AutoSetContractAsync(newObj); await AutoSetContractAsync(newObj);
} }
} }
} }
private async Task AutoSetContractAsync(WorkOrder newObj) private async Task AutoSetContractAsync(WorkOrder newObj)
{ {
//first reset contract fetched flag so a fresh copy is taken
//in case it was set already by other operations
mFetchedContractAlready = false;
//CONTRACT AUTO SET //CONTRACT AUTO SET
if (newObj.ContractId == null && newObj.CustomerId != 0) if (newObj.CustomerId != 0)
{ {
//unit->customer->headoffice //unit->customer->headoffice
var cust = await ct.Customer.AsNoTracking().Where(z => z.Id == newObj.CustomerId).Select(z => new { headofficeId = z.HeadOfficeId, contractId = z.ContractId }).FirstOrDefaultAsync(); var cust = await ct.Customer.AsNoTracking().Where(z => z.Id == newObj.CustomerId).Select(z => new { headofficeId = z.HeadOfficeId, contractId = z.ContractId }).FirstOrDefaultAsync();
@@ -354,7 +360,9 @@ namespace AyaNova.Biz
newObj.ContractId = hoContractId; newObj.ContractId = hoContractId;
} }
else else
newObj.ContractId = cust.contractId; newObj.ContractId = cust.contractId;//if ultimately no contract for this customer or ho then it's set to null anyway which is what we want
}else{
newObj.ContractId=null;//no customer then contract
} }
//RESPONSE TIME / COMPLETE BY AUTO SET //RESPONSE TIME / COMPLETE BY AUTO SET