diff --git a/.vscode/launch.json b/.vscode/launch.json index 8fd97968..0e2049e9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,7 +53,7 @@ "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", - "AYANOVA_SERVER_TEST_MODE": "true", + "AYANOVA_SERVER_TEST_MODE": "false", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" diff --git a/server/AyaNova/biz/CustomerBiz.cs b/server/AyaNova/biz/CustomerBiz.cs index e576217f..7bcad4b4 100644 --- a/server/AyaNova/biz/CustomerBiz.cs +++ b/server/AyaNova/biz/CustomerBiz.cs @@ -151,9 +151,7 @@ namespace AyaNova.Biz try { Customer dbObject = await ct.Customer.SingleOrDefaultAsync(z => z.Id == id); - ValidateCanDelete(dbObject); - if (HasErrors) - return false; + await ValidateCanDelete(dbObject); if (HasErrors) return false; ct.Customer.Remove(dbObject); @@ -169,6 +167,7 @@ namespace AyaNova.Biz } catch { + //Just re-throw for now, let exception handler deal, but in future may want to deal with this more here throw; } @@ -246,9 +245,20 @@ namespace AyaNova.Biz } - private void ValidateCanDelete(Customer inObj) + + private async Task ValidateCanDelete(Customer inObj) { - //whatever needs to be check to delete this object + //## NOTE: contact isn't so important, this could be changed to check only more important things like workorders etc + //and just attempt to delete all the contacts if possible, but for now.... + + //Referential integrity error + if (await ct.User.AnyAsync(z => z.CustomerId == inObj.Id) == true) + { + //Note: errorbox will ensure it appears in the general errror box and not field specific + //the translation key is to indicate what the linked object is that is causing the error + AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "errorbox", "LT:Contact"); + } + } diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index ad4d085e..64468370 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -206,7 +206,7 @@ namespace AyaNova.Biz try { Report dbObject = await ct.Report.SingleOrDefaultAsync(z => z.Id == id); - ValidateCanDelete(dbObject); + await ValidateCanDelete(dbObject); if (HasErrors) return false; ct.Report.Remove(dbObject); @@ -296,16 +296,15 @@ namespace AyaNova.Biz } - private async void ValidateCanDelete(Report inObj) + private async Task ValidateCanDelete(Report inObj) { - - //TODO: this is shitty, needs to mention notifications to be maximally useful + //Referential integrity error if (await ct.NotifySubscription.AnyAsync(z => z.LinkReportId == inObj.Id) == true) { - AddError(ApiErrorCode.INVALID_OPERATION, null, "LT:ErrorDBForeignKeyViolation"); - return; + //Note: errorbox will ensure it appears in the general errror box and not field specific + //the translation key is to indicate what the linked object is that is causing the error + AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "errorbox", "LT:NotifySubscription"); } - } diff --git a/server/AyaNova/biz/VendorBiz.cs b/server/AyaNova/biz/VendorBiz.cs index 136de917..6c53b4b8 100644 --- a/server/AyaNova/biz/VendorBiz.cs +++ b/server/AyaNova/biz/VendorBiz.cs @@ -153,9 +153,7 @@ namespace AyaNova.Biz Vendor dbObject = await ct.Vendor.SingleOrDefaultAsync(z => z.Id == id); ValidateCanDelete(dbObject); if (HasErrors) - return false; - if (HasErrors) - return false; + return false; ct.Vendor.Remove(dbObject); await ct.SaveChangesAsync(); await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct); diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs index 44f0a28e..8670b32a 100644 --- a/server/AyaNova/util/DbUtil.cs +++ b/server/AyaNova/util/DbUtil.cs @@ -609,6 +609,7 @@ namespace AyaNova.Util + }//eoc }//eons \ No newline at end of file