This commit is contained in:
@@ -139,6 +139,7 @@ namespace AyaNova.Biz
|
||||
await PartBizActionsAsync(AyaEvent.Created, wip, null, null);
|
||||
foreach (WorkOrderItemLoan wil in wi.Loans)
|
||||
await LoanBizActionsAsync(AyaEvent.Created, wil, null, null);
|
||||
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
@@ -2336,9 +2337,6 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//await ExpenseBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
// newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
// newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemExpense.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||
@@ -2384,11 +2382,9 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||
return null;
|
||||
}
|
||||
// dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
||||
|
||||
await ExpenseValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
//await ExpenseBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
@@ -2404,7 +2400,6 @@ namespace AyaNova.Biz
|
||||
}
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, putObject.Id, putObject.AyaType, AyaEvent.Modified), ct);
|
||||
await ExpenseSearchIndexAsync(putObject, false);
|
||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
|
||||
await ExpenseHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||
await ExpensePopulateVizFields(putObject);
|
||||
return putObject;
|
||||
@@ -2758,12 +2753,9 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
}
|
||||
|
||||
//dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
||||
//dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
||||
|
||||
await LaborValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
// await LaborBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
@@ -3117,8 +3109,6 @@ namespace AyaNova.Biz
|
||||
else
|
||||
{
|
||||
await LoanBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
//newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemLoan.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||
@@ -3161,9 +3151,6 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
}
|
||||
|
||||
// dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
||||
|
||||
await LoanValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
await LoanBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
@@ -5587,14 +5574,10 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//await TravelBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
//newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
//newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemTravel.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||
await TravelSearchIndexAsync(newObject, true);
|
||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||
await TravelHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||
await TravelPopulateVizFields(newObject);
|
||||
return newObject;
|
||||
@@ -5634,11 +5617,8 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
}
|
||||
|
||||
//dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
||||
await TravelValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
// await TravelBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
@@ -5959,8 +5939,9 @@ namespace AyaNova.Biz
|
||||
|
||||
#region WorkOrderItemUnit level
|
||||
|
||||
//this is set by validation for further processing later if applicable
|
||||
private Contract currentUnitContract = null;
|
||||
//this is set by validation for further processing if applicable
|
||||
private long? newOrChangedActiveUnitContractId = null;
|
||||
private long newOrChangedActiveUnitWorkOrderId = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//EXISTS
|
||||
@@ -5983,7 +5964,7 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//TODO: In biz actions set contract if this unit has a contract, note that we are only here if there is no pre-existing unit with a contract on this workorder via validation above
|
||||
//await UnitBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
||||
newObject.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||
await ct.WorkOrderItemUnit.AddAsync(newObject);
|
||||
@@ -5993,6 +5974,15 @@ namespace AyaNova.Biz
|
||||
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||
await UnitPopulateVizFields(newObject);
|
||||
|
||||
//update workorder with new contract??
|
||||
//Note this is determined if applicable and set during validation
|
||||
if (newOrChangedActiveUnitContractId != null && newOrChangedActiveUnitWorkOrderId != 0)
|
||||
{
|
||||
WorkOrder w = await ct.WorkOrder.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newOrChangedActiveUnitWorkOrderId);
|
||||
w.ContractId = newOrChangedActiveUnitContractId;
|
||||
await WorkOrderPutAsync(w);
|
||||
}
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
@@ -6032,7 +6022,6 @@ namespace AyaNova.Biz
|
||||
await UnitValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
|
||||
//TODO: In biz actions set contract if this unit has a contract, note that we are only here if there is no pre-existing unit with a contract on this workorder via validation above
|
||||
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
@@ -6052,6 +6041,15 @@ namespace AyaNova.Biz
|
||||
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
|
||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||
await UnitPopulateVizFields(putObject);
|
||||
|
||||
//update workorder with new contract??
|
||||
//Note this is determined if applicable and set during validation
|
||||
if (newOrChangedActiveUnitContractId != null && newOrChangedActiveUnitWorkOrderId != 0)
|
||||
{
|
||||
WorkOrder w = await ct.WorkOrder.AsNoTracking().FirstOrDefaultAsync(z => z.Id == newOrChangedActiveUnitWorkOrderId);
|
||||
w.ContractId = newOrChangedActiveUnitContractId;
|
||||
await WorkOrderPutAsync(w);
|
||||
}
|
||||
return putObject;
|
||||
}
|
||||
|
||||
@@ -6073,8 +6071,6 @@ namespace AyaNova.Biz
|
||||
//Log event
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, dbObject.AyaType, dbObject.Id, "woitem:" + dbObject.WorkOrderItemId.ToString(), ct);//Fix??
|
||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, dbObject.AyaType, ct);
|
||||
//await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
|
||||
//await FileUtil.DeleteAttachmentsForObjectAsync(dbObject.AyaType, dbObject.Id, ct);
|
||||
if (parentTransaction == null)
|
||||
await transaction.CommitAsync();
|
||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
||||
@@ -6113,6 +6109,42 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //BIZ ACTIONS
|
||||
// //
|
||||
// //
|
||||
// private async Task UnitBizActionsAsync(AyaEvent ayaEvent, WorkOrderItemUnit newObj, WorkOrderItemUnit oldObj, IDbContextTransaction transaction)
|
||||
// {
|
||||
// //automatic actions on record change, called AFTER validation
|
||||
|
||||
// //currently no processing required except for created or modified at this time
|
||||
// if (ayaEvent != AyaEvent.Created && ayaEvent != AyaEvent.Modified)
|
||||
// return;
|
||||
|
||||
|
||||
// if (newOrChangedActiveUnitContract != null && (ayaEvent == AyaEvent.Modified || ayaEvent == AyaEvent.Created))//note: keeping this qualification defensively in case more biz actions added later
|
||||
// {
|
||||
// //set contract if applicable
|
||||
// //Note: validation has already set neworchangeactiveunitcontract and only sets it if it's applicable
|
||||
// //so in here we just need to apply that contract to the header
|
||||
// //I've decided that it will attempt to set the header here now rather than after the unit has set
|
||||
// //as it's more important to have the unit record be saved than to
|
||||
|
||||
|
||||
// // //If it wasn't a complete part change there is no need to set pricing
|
||||
// // if (newObj.LoanUnitId == oldObj.LoanUnitId && newObj.Rate == oldObj.Rate)
|
||||
// // {
|
||||
// // SnapshotPricing = false;
|
||||
// // //maintain old cost as it can come from the client as zero when it shouldn't be or someone using the api and setting it directly
|
||||
// // //but we will only allow the price *we* set at the server initially
|
||||
// // newObj.Cost = oldObj.Cost;
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VIZ POPULATE
|
||||
//
|
||||
@@ -6141,7 +6173,6 @@ namespace AyaNova.Biz
|
||||
//skip validation if seeding
|
||||
// if (ServerBootConfig.SEEDING) return;
|
||||
|
||||
//TODO: ADD VALIDATIONS:
|
||||
// - A work order *MUST* have only one Unit with a Contract, if there is already a unit with a contract on this workorder then a new one cannot be added and it will reject with a validation error
|
||||
// a unit record is saved only *after* there is already a header (by api users and our client software) so can easily check and set here
|
||||
|
||||
@@ -6181,8 +6212,6 @@ namespace AyaNova.Biz
|
||||
if (proposedObj.UnitId < 1 || !await ct.Unit.AnyAsync(x => x.Id == proposedObj.UnitId))
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UnitId");
|
||||
|
||||
|
||||
|
||||
//Contracted unit? Only one per work order is allowed
|
||||
if (isNew || proposedObj.UnitId != currentObj.UnitId)
|
||||
{
|
||||
@@ -6193,11 +6222,12 @@ namespace AyaNova.Biz
|
||||
if (proposedUnitInfo.ContractId != null && proposedUnitInfo.ContractExpires > DateTime.UtcNow)
|
||||
{
|
||||
//added woitemunit has a contract and apparently unexpired so need to check if contract is still active
|
||||
currentUnitContract = await GetFullyPopulatedContractGraphFromIdAsync(proposedUnitInfo.ContractId);
|
||||
if (currentUnitContract != null && currentUnitContract.Active)
|
||||
newOrChangedActiveUnitContractId = proposedUnitInfo.ContractId;
|
||||
if (await ct.Contract.AsNoTracking().Where(z => z.Id == proposedUnitInfo.ContractId).Select(x => x.Active).FirstOrDefaultAsync() == true)
|
||||
{
|
||||
//iterate work order and check for other contracted unit
|
||||
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, proposedObj.WorkOrderItemId, ct);
|
||||
newOrChangedActiveUnitWorkOrderId = woId.WorkOrderId;//save for later contract update if necessary
|
||||
var w = await WorkOrderGetFullAsync(woId.WorkOrderId);
|
||||
|
||||
//iterate, look for *other* woitemunit records, are they contracted already?
|
||||
@@ -6232,7 +6262,7 @@ namespace AyaNova.Biz
|
||||
}
|
||||
else
|
||||
{
|
||||
currentUnitContract = null;//just in case it's non active but present so later biz actions don't process it
|
||||
newOrChangedActiveUnitContractId = null;//just in case it's non active but present so later biz actions don't process it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user