This commit is contained in:
@@ -139,6 +139,7 @@ namespace AyaNova.Biz
|
|||||||
await PartBizActionsAsync(AyaEvent.Created, wip, null, null);
|
await PartBizActionsAsync(AyaEvent.Created, wip, null, null);
|
||||||
foreach (WorkOrderItemLoan wil in wi.Loans)
|
foreach (WorkOrderItemLoan wil in wi.Loans)
|
||||||
await LoanBizActionsAsync(AyaEvent.Created, wil, null, null);
|
await LoanBizActionsAsync(AyaEvent.Created, wil, null, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -2336,9 +2337,6 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
else
|
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.WorkOrderItemExpense.AddAsync(newObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||||
@@ -2384,11 +2382,9 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
|
||||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
|
||||||
await ExpenseValidateAsync(putObject, dbObject);
|
await ExpenseValidateAsync(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
if (HasErrors) return null;
|
||||||
//await ExpenseBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
|
||||||
ct.Replace(dbObject, putObject);
|
ct.Replace(dbObject, putObject);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -2404,7 +2400,6 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, putObject.Id, putObject.AyaType, AyaEvent.Modified), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, putObject.Id, putObject.AyaType, AyaEvent.Modified), ct);
|
||||||
await ExpenseSearchIndexAsync(putObject, false);
|
await ExpenseSearchIndexAsync(putObject, false);
|
||||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
|
|
||||||
await ExpenseHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
await ExpenseHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||||
await ExpensePopulateVizFields(putObject);
|
await ExpensePopulateVizFields(putObject);
|
||||||
return putObject;
|
return putObject;
|
||||||
@@ -2758,12 +2753,9 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
|
||||||
//dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
|
||||||
|
|
||||||
await LaborValidateAsync(putObject, dbObject);
|
await LaborValidateAsync(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
if (HasErrors) return null;
|
||||||
// await LaborBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
|
||||||
ct.Replace(dbObject, putObject);
|
ct.Replace(dbObject, putObject);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -3117,8 +3109,6 @@ namespace AyaNova.Biz
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
await LoanBizActionsAsync(AyaEvent.Created, newObject, null, null);
|
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.WorkOrderItemLoan.AddAsync(newObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||||
@@ -3161,9 +3151,6 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
|
||||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
|
||||||
|
|
||||||
await LoanValidateAsync(putObject, dbObject);
|
await LoanValidateAsync(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
if (HasErrors) return null;
|
||||||
await LoanBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
await LoanBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
||||||
@@ -5587,14 +5574,10 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
else
|
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.WorkOrderItemTravel.AddAsync(newObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, newObject.AyaType, AyaEvent.Created), ct);
|
||||||
await TravelSearchIndexAsync(newObject, true);
|
await TravelSearchIndexAsync(newObject, true);
|
||||||
//await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
|
||||||
await TravelHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
await TravelHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||||
await TravelPopulateVizFields(newObject);
|
await TravelPopulateVizFields(newObject);
|
||||||
return newObject;
|
return newObject;
|
||||||
@@ -5634,11 +5617,8 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
|
|
||||||
// dbObject.CustomFields = JsonUtil.CompactJson(dbObject.CustomFields);
|
|
||||||
await TravelValidateAsync(putObject, dbObject);
|
await TravelValidateAsync(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
if (HasErrors) return null;
|
||||||
// await TravelBizActionsAsync(AyaEvent.Modified, putObject, dbObject, null);
|
|
||||||
ct.Replace(dbObject, putObject);
|
ct.Replace(dbObject, putObject);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -5959,8 +5939,9 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
#region WorkOrderItemUnit level
|
#region WorkOrderItemUnit level
|
||||||
|
|
||||||
//this is set by validation for further processing later if applicable
|
//this is set by validation for further processing if applicable
|
||||||
private Contract currentUnitContract = null;
|
private long? newOrChangedActiveUnitContractId = null;
|
||||||
|
private long newOrChangedActiveUnitWorkOrderId = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//EXISTS
|
//EXISTS
|
||||||
@@ -5983,7 +5964,7 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
else
|
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.Tags = TagBiz.NormalizeTags(newObject.Tags);
|
||||||
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
newObject.CustomFields = JsonUtil.CompactJson(newObject.CustomFields);
|
||||||
await ct.WorkOrderItemUnit.AddAsync(newObject);
|
await ct.WorkOrderItemUnit.AddAsync(newObject);
|
||||||
@@ -5993,6 +5974,15 @@ namespace AyaNova.Biz
|
|||||||
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
|
||||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
await UnitHandlePotentialNotificationEvent(AyaEvent.Created, newObject);
|
||||||
await UnitPopulateVizFields(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;
|
return newObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6032,7 +6022,6 @@ namespace AyaNova.Biz
|
|||||||
await UnitValidateAsync(putObject, dbObject);
|
await UnitValidateAsync(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
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);
|
ct.Replace(dbObject, putObject);
|
||||||
try
|
try
|
||||||
@@ -6052,6 +6041,15 @@ namespace AyaNova.Biz
|
|||||||
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
|
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
|
||||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
await UnitHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||||
await UnitPopulateVizFields(putObject);
|
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;
|
return putObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6073,8 +6071,6 @@ namespace AyaNova.Biz
|
|||||||
//Log event
|
//Log event
|
||||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, dbObject.AyaType, dbObject.Id, "woitem:" + dbObject.WorkOrderItemId.ToString(), ct);//Fix??
|
await EventLogProcessor.DeleteObjectLogAsync(UserId, dbObject.AyaType, dbObject.Id, "woitem:" + dbObject.WorkOrderItemId.ToString(), ct);//Fix??
|
||||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, dbObject.AyaType, ct);
|
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)
|
if (parentTransaction == null)
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
await UnitHandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
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
|
//VIZ POPULATE
|
||||||
//
|
//
|
||||||
@@ -6141,7 +6173,6 @@ namespace AyaNova.Biz
|
|||||||
//skip validation if seeding
|
//skip validation if seeding
|
||||||
// if (ServerBootConfig.SEEDING) return;
|
// 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 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
|
// 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))
|
if (proposedObj.UnitId < 1 || !await ct.Unit.AnyAsync(x => x.Id == proposedObj.UnitId))
|
||||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UnitId");
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UnitId");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Contracted unit? Only one per work order is allowed
|
//Contracted unit? Only one per work order is allowed
|
||||||
if (isNew || proposedObj.UnitId != currentObj.UnitId)
|
if (isNew || proposedObj.UnitId != currentObj.UnitId)
|
||||||
{
|
{
|
||||||
@@ -6193,11 +6222,12 @@ namespace AyaNova.Biz
|
|||||||
if (proposedUnitInfo.ContractId != null && proposedUnitInfo.ContractExpires > DateTime.UtcNow)
|
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
|
//added woitemunit has a contract and apparently unexpired so need to check if contract is still active
|
||||||
currentUnitContract = await GetFullyPopulatedContractGraphFromIdAsync(proposedUnitInfo.ContractId);
|
newOrChangedActiveUnitContractId = proposedUnitInfo.ContractId;
|
||||||
if (currentUnitContract != null && currentUnitContract.Active)
|
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
|
//iterate work order and check for other contracted unit
|
||||||
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, proposedObj.WorkOrderItemId, ct);
|
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);
|
var w = await WorkOrderGetFullAsync(woId.WorkOrderId);
|
||||||
|
|
||||||
//iterate, look for *other* woitemunit records, are they contracted already?
|
//iterate, look for *other* woitemunit records, are they contracted already?
|
||||||
@@ -6232,7 +6262,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
else
|
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