diff --git a/server/AyaNova/biz/PartWarehouseBiz.cs b/server/AyaNova/biz/PartWarehouseBiz.cs index 55426a1c..4649f7f6 100644 --- a/server/AyaNova/biz/PartWarehouseBiz.cs +++ b/server/AyaNova/biz/PartWarehouseBiz.cs @@ -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"); + } + }