This commit is contained in:
2020-12-03 23:54:57 +00:00
parent 0b7610be86
commit a7fdbcf0fd
5 changed files with 24 additions and 16 deletions

2
.vscode/launch.json vendored
View File

@@ -53,7 +53,7 @@
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", "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_SEEDLEVEL": "small",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7",
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\"

View File

@@ -151,9 +151,7 @@ namespace AyaNova.Biz
try try
{ {
Customer dbObject = await ct.Customer.SingleOrDefaultAsync(z => z.Id == id); Customer dbObject = await ct.Customer.SingleOrDefaultAsync(z => z.Id == id);
ValidateCanDelete(dbObject); await ValidateCanDelete(dbObject);
if (HasErrors)
return false;
if (HasErrors) if (HasErrors)
return false; return false;
ct.Customer.Remove(dbObject); ct.Customer.Remove(dbObject);
@@ -169,6 +167,7 @@ namespace AyaNova.Biz
} }
catch catch
{ {
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here //Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
throw; 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");
}
} }

View File

@@ -206,7 +206,7 @@ namespace AyaNova.Biz
try try
{ {
Report dbObject = await ct.Report.SingleOrDefaultAsync(z => z.Id == id); Report dbObject = await ct.Report.SingleOrDefaultAsync(z => z.Id == id);
ValidateCanDelete(dbObject); await ValidateCanDelete(dbObject);
if (HasErrors) if (HasErrors)
return false; return false;
ct.Report.Remove(dbObject); ct.Report.Remove(dbObject);
@@ -296,16 +296,15 @@ namespace AyaNova.Biz
} }
private async void ValidateCanDelete(Report inObj) private async Task ValidateCanDelete(Report inObj)
{ {
//Referential integrity error
//TODO: this is shitty, needs to mention notifications to be maximally useful
if (await ct.NotifySubscription.AnyAsync(z => z.LinkReportId == inObj.Id) == true) if (await ct.NotifySubscription.AnyAsync(z => z.LinkReportId == inObj.Id) == true)
{ {
AddError(ApiErrorCode.INVALID_OPERATION, null, "LT:ErrorDBForeignKeyViolation"); //Note: errorbox will ensure it appears in the general errror box and not field specific
return; //the translation key is to indicate what the linked object is that is causing the error
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "errorbox", "LT:NotifySubscription");
} }
} }

View File

@@ -153,9 +153,7 @@ namespace AyaNova.Biz
Vendor dbObject = await ct.Vendor.SingleOrDefaultAsync(z => z.Id == id); Vendor dbObject = await ct.Vendor.SingleOrDefaultAsync(z => z.Id == id);
ValidateCanDelete(dbObject); ValidateCanDelete(dbObject);
if (HasErrors) if (HasErrors)
return false; return false;
if (HasErrors)
return false;
ct.Vendor.Remove(dbObject); ct.Vendor.Remove(dbObject);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct); await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct);

View File

@@ -609,6 +609,7 @@ namespace AyaNova.Util
}//eoc }//eoc
}//eons }//eons