|
|
|
|
@@ -12,21 +12,11 @@ using System.Collections.Generic;
|
|
|
|
|
namespace AyaNova.Biz
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
###############
|
|
|
|
|
MUST be able to update any section at any level independantly
|
|
|
|
|
Fetch must be able to get entire graph or from any level down or single header only as required
|
|
|
|
|
probably need a woheaderfetch route separately
|
|
|
|
|
|
|
|
|
|
TODO: Routes then front end stuff can start and may god have mercy on my soul! ;)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
todo: Don't all *child items require a transaction to be passed for *any* crud op, i.e. including put and etc?
|
|
|
|
|
As they might be called from a parent transaction?
|
|
|
|
|
(wait until front end to decide this and do some testing etc grok it out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
###############
|
|
|
|
|
todo: Don't all *child items require a transaction to be passed for *any* crud op, i.e. including put and etc?
|
|
|
|
|
As they might be called from a parent transaction?
|
|
|
|
|
(wait until front end to decide this and do some testing etc grok it out)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
internal class WorkOrderBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject
|
|
|
|
|
{
|
|
|
|
|
@@ -173,6 +163,8 @@ namespace AyaNova.Biz
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
putObject.Tags = TagBiz.NormalizeTags(putObject.Tags);
|
|
|
|
|
putObject.CustomFields = JsonUtil.CompactJson(putObject.CustomFields);
|
|
|
|
|
await WorkOrderValidateAsync(putObject, dbObject);
|
|
|
|
|
@@ -350,6 +342,19 @@ namespace AyaNova.Biz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if (!isNew)
|
|
|
|
|
{
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if (CurrentWoStatus.Locked)
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
@@ -1056,6 +1061,19 @@ namespace AyaNova.Biz
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if (!isNew)
|
|
|
|
|
{
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if (CurrentWoStatus.Locked)
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.WorkOrderItem.ToString());
|
|
|
|
|
if (FormCustomization != null)
|
|
|
|
|
@@ -1293,6 +1311,20 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if (!isNew)
|
|
|
|
|
{
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if (CurrentWoStatus.Locked)
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.WorkOrderItemExpense.ToString());
|
|
|
|
|
if (FormCustomization != null)
|
|
|
|
|
@@ -1530,6 +1562,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -1769,6 +1812,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -2020,6 +2074,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -2261,6 +2326,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -2476,6 +2552,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -2692,6 +2779,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -2932,6 +3030,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -3173,6 +3282,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -3414,6 +3534,17 @@ namespace AyaNova.Biz
|
|
|
|
|
else if (!await ItemExistsAsync(proposedObj.WorkOrderItemId))
|
|
|
|
|
{
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "WorkOrderItemId");
|
|
|
|
|
}
|
|
|
|
|
//Check state if updatable right now
|
|
|
|
|
if(!isNew){
|
|
|
|
|
//Front end is coded to save the state first before any other updates if it has changed and it would not be
|
|
|
|
|
//a part of this header update so it's safe to check it here as it will be most up to date
|
|
|
|
|
var CurrentWoStatus = await GetCurrentWorkOrderStatusFromRelatedAsync(proposedObj.AyaType, proposedObj.Id);
|
|
|
|
|
if(CurrentWoStatus.Locked){
|
|
|
|
|
AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", await Translate("WorkOrderErrorLocked"));
|
|
|
|
|
return;//this is a completely disqualifying error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Any form customizations to validate?
|
|
|
|
|
@@ -3606,12 +3737,17 @@ namespace AyaNova.Biz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//GET UPDATEABLE STATUS FOR WORKORDER FROM DESCENDANT
|
|
|
|
|
//GET CURRENT STATUS FOR WORKORDER FROM RELATIVE
|
|
|
|
|
//
|
|
|
|
|
internal async Task<WorkOrderStatus> GetCurrentWorkOrderStatusFromRelatedAsync(AyaType ayaType, long id)
|
|
|
|
|
{
|
|
|
|
|
//instantiated method to save adding the context
|
|
|
|
|
return await GetCurrentWorkOrderStatusFromRelatedAsync(ayaType, id, ct);
|
|
|
|
|
}
|
|
|
|
|
internal static async Task<WorkOrderStatus> GetCurrentWorkOrderStatusFromRelatedAsync(AyaType ayaType, long id, AyContext ct)
|
|
|
|
|
{
|
|
|
|
|
//static method
|
|
|
|
|
long WoId = await GetWorkOrderIdFromRelativeAsync(ayaType, id, ct);
|
|
|
|
|
|
|
|
|
|
return await ct.WorkOrderState.AsNoTracking()
|
|
|
|
|
.Include(z => z.WorkOrderStatus)
|
|
|
|
|
.Where(z => z.WorkOrderId == WoId)
|
|
|
|
|
@@ -3619,8 +3755,10 @@ namespace AyaNova.Biz
|
|
|
|
|
.Select(z => z.WorkOrderStatus)
|
|
|
|
|
.Take(1)
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion utility
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|