This commit is contained in:
2021-02-11 00:53:48 +00:00
parent 0749539172
commit 8fdfa3482d
9 changed files with 72 additions and 48 deletions

View File

@@ -160,7 +160,7 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.NOT_FOUND);
return false;
}
await ValidateCanDelete(dbObject);
await ValidateCanDeleteAsync(dbObject);
if (HasErrors)
return false;
ct.PartWarehouse.Remove(dbObject);
@@ -257,24 +257,20 @@ namespace AyaNova.Biz
}
}
private async Task ValidateCanDelete(PartWarehouse inObj)
{
//Can't delete the default warehouse
private async Task ValidateCanDeleteAsync(PartWarehouse inObj)
{//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?
//Referential integrity
if (await ct.PartInventory.AnyAsync(m => m.PartWarehouseId == inObj.Id))
{
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartInventoryTransaction"));
}
if (await ct.PartStockLevel.AnyAsync(m => m.PartWarehouseId == inObj.Id))
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartStockingLevels"));
}