This commit is contained in:
@@ -160,7 +160,7 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
ValidateCanDelete(dbObject);
|
||||
await ValidateCanDeleteAsync(dbObject);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.Vendor.Remove(dbObject);
|
||||
@@ -282,9 +282,24 @@ namespace AyaNova.Biz
|
||||
|
||||
}
|
||||
|
||||
private void ValidateCanDelete(Vendor inObj)
|
||||
|
||||
private async Task ValidateCanDeleteAsync(Vendor inObj)
|
||||
{
|
||||
//whatever needs to be check to delete this object
|
||||
//Referential integrity
|
||||
//FOREIGN KEY CHECKS
|
||||
if (await ct.User.AnyAsync(m => m.VendorId == inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("User"));
|
||||
if (await ct.UnitModel.AnyAsync(m => m.VendorId == inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("UnitModel"));
|
||||
if (await ct.Unit.AnyAsync(m => m.PurchasedFromVendorId == inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Unit"));
|
||||
//part has three potential references, if any match that's good enough since it's the same message
|
||||
if (await ct.Part.AnyAsync(z => z.ManufacturerId == inObj.Id) == true)
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Part"));
|
||||
else if (await ct.Part.AnyAsync(z => z.WholeSalerId == inObj.Id) == true)
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Part"));
|
||||
else if (await ct.Part.AnyAsync(z => z.AlternativeWholeSalerId == inObj.Id) == true)
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Part"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user