This commit is contained in:
2021-01-23 00:29:31 +00:00
parent a0f374ac1e
commit 9f6be8315b

View File

@@ -155,9 +155,7 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.NOT_FOUND);
return false;
}
ValidateCanDelete(dbObject);
if (HasErrors)
return false;
await ValidateCanDelete(dbObject);
if (HasErrors)
return false;
ct.PartWarehouse.Remove(dbObject);
@@ -240,7 +238,6 @@ namespace AyaNova.Biz
}
}
//Any form customizations to validate?
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(x => x.FormKey == AyaType.PartWarehouse.ToString());
if (FormCustomization != null)
@@ -253,18 +250,26 @@ namespace AyaNova.Biz
//validate custom fields
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
}
}
private void ValidateCanDelete(PartWarehouse inObj)
private async Task ValidateCanDelete(PartWarehouse inObj)
{
//whatever needs to be check to delete this object
//Can't delete the default warehouse
if (inObj.Id == 1)
{
AddError(ApiErrorCode.INVALID_OPERATION, "generalerror", "Default part warehouse can not be deleted");
return;//nothing more need be checked this is completetly disqualifying
}
//FOREIGN KEY CHECKS
//PartInventory record?
if (await ct.PartInventory.AnyAsync(m => m.PartWarehouseId == inObj.Id))
{
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", "LT:PartInventory");
}
}