This commit is contained in:
@@ -156,7 +156,7 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ValidateCanDelete(dbObject);
|
await ValidateCanDeleteAsync(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
@@ -255,9 +255,13 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ValidateCanDelete(Contract inObj)
|
private async Task ValidateCanDeleteAsync(Contract inObj)
|
||||||
{
|
{
|
||||||
//whatever needs to be check to delete this object
|
//FOREIGN KEY CHECKS
|
||||||
|
if (await ct.Customer.AnyAsync(m => m.ContractId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Customer"));
|
||||||
|
if (await ct.HeadOffice.AnyAsync(m => m.ContractId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("HeadOffice"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -120,10 +120,10 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
putObject.Tags = TagBiz.NormalizeTags(putObject.Tags);
|
putObject.Tags = TagBiz.NormalizeTags(putObject.Tags);
|
||||||
putObject.CustomFields = JsonUtil.CompactJson(putObject.CustomFields);
|
putObject.CustomFields = JsonUtil.CompactJson(putObject.CustomFields);
|
||||||
await ValidateAsync(putObject, dbObject);
|
await ValidateAsync(putObject, dbObject);
|
||||||
if (HasErrors) return null;
|
if (HasErrors) return null;
|
||||||
ct.Replace(dbObject, putObject);
|
ct.Replace(dbObject, putObject);
|
||||||
try
|
try
|
||||||
@@ -335,14 +335,12 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Referential integrity error
|
//FOREIGN KEY CHECKS
|
||||||
//Just an example
|
if (await ct.User.AnyAsync(m => m.CustomerId == inObj.Id))
|
||||||
// if (await ct.User.AnyAsync(z => z.CustomerId == inObj.Id) == true)
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("User"));
|
||||||
// {
|
if (await ct.Unit.AnyAsync(m => m.CustomerId == inObj.Id))
|
||||||
// //Note: errorbox will ensure it appears in the general errror box and not field specific
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Unit"));
|
||||||
// //the translation key is to indicate what the linked object is that is causing the error
|
|
||||||
// AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", "LT:Contact");
|
|
||||||
// }
|
|
||||||
|
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,12 +300,11 @@ namespace AyaNova.Biz
|
|||||||
private async Task ValidateCanDeleteAsync(HeadOffice inObj)
|
private async Task ValidateCanDeleteAsync(HeadOffice inObj)
|
||||||
{
|
{
|
||||||
//Referential integrity
|
//Referential integrity
|
||||||
|
//FOREIGN KEY CHECKS
|
||||||
|
if (await ct.User.AnyAsync(m => m.HeadOfficeId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("User"));
|
||||||
if (await ct.Customer.AnyAsync(z => z.HeadOfficeId == inObj.Id) == true)
|
if (await ct.Customer.AnyAsync(z => z.HeadOfficeId == 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, "generalerror", await Translate("Customer"));
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Customer"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ValidateCanDelete(dbObject);
|
await ValidateCanDeleteAsync(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
@@ -399,9 +399,20 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ValidateCanDelete(Part inObj)
|
|
||||||
|
private async Task ValidateCanDeleteAsync(Part inObj)
|
||||||
{
|
{
|
||||||
//whatever needs to be check to delete this object
|
//Referential integrity
|
||||||
|
//FOREIGN KEY CHECKS
|
||||||
|
if (await ct.PartSerial.AnyAsync(m => m.PartId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartSerial"));
|
||||||
|
if (await ct.PartAssemblyItem.AnyAsync(z => z.PartId == inObj.Id) == true)
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartAssembly"));
|
||||||
|
if (await ct.PartInventory.AnyAsync(z => z.PartId == inObj.Id) == true)
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartInventoryList"));//translates to "Part inventory"
|
||||||
|
if (await ct.PartStockLevel.AnyAsync(m => m.PartId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartStockingLevels"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await ValidateCanDelete(dbObject);
|
await ValidateCanDeleteAsync(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
ct.PartWarehouse.Remove(dbObject);
|
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)
|
if (inObj.Id == 1)
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.INVALID_OPERATION, "generalerror", "Default part warehouse can not be deleted");
|
AddError(ApiErrorCode.INVALID_OPERATION, "generalerror", "Default part warehouse can not be deleted");
|
||||||
return;//nothing more need be checked this is completetly disqualifying
|
return;//nothing more need be checked this is completetly disqualifying
|
||||||
}
|
}
|
||||||
|
//Referential integrity
|
||||||
//FOREIGN KEY CHECKS
|
|
||||||
|
|
||||||
//PartInventory record?
|
|
||||||
if (await ct.PartInventory.AnyAsync(m => m.PartWarehouseId == inObj.Id))
|
if (await ct.PartInventory.AnyAsync(m => m.PartWarehouseId == inObj.Id))
|
||||||
{
|
|
||||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("PartInventoryTransaction"));
|
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"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await ValidateCanDelete(dbObject);
|
await ValidateCanDeleteAsync(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
@@ -271,16 +271,15 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ValidateCanDelete(Unit inObj)
|
private async Task ValidateCanDeleteAsync(Unit inObj)
|
||||||
{
|
{
|
||||||
//whatever needs to be check to delete this object
|
//FOREIGN KEY CHECKS
|
||||||
|
if (await ct.Unit.AnyAsync(m => m.ParentUnitId == inObj.Id))
|
||||||
//Can't delete a unit if it's a shadow unit for a loanunit
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("UnitParentUnitID"));
|
||||||
|
if (await ct.Unit.AnyAsync(m => m.ReplacedByUnitId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("UnitReplacedByUnitID"));
|
||||||
if (await ct.LoanUnit.AnyAsync(z => z.UnitId == inObj.Id))
|
if (await ct.LoanUnit.AnyAsync(z => z.UnitId == inObj.Id))
|
||||||
{
|
|
||||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("LoanUnit"));
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("LoanUnit"));
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ValidateCanDelete(dbObject);
|
await ValidateCanDeleteAsync(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
@@ -264,11 +264,14 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ValidateCanDelete(UnitModel inObj)
|
|
||||||
{
|
|
||||||
//whatever needs to be check to delete this object
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private async Task ValidateCanDeleteAsync(UnitModel inObj)
|
||||||
|
{
|
||||||
|
//FOREIGN KEY CHECKS
|
||||||
|
if (await ct.Unit.AnyAsync(m => m.UnitModelId == inObj.Id))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("Unit"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace AyaNova.Biz
|
|||||||
AddError(ApiErrorCode.NOT_FOUND);
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ValidateCanDelete(dbObject);
|
await ValidateCanDeleteAsync(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
ct.Vendor.Remove(dbObject);
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -499,7 +499,6 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
|||||||
await ExecQueryAsync("CREATE TABLE aopsjob (gid uuid PRIMARY KEY, name TEXT NOT NULL, created TIMESTAMP NOT NULL, exclusive BOOL NOT NULL, " +
|
await ExecQueryAsync("CREATE TABLE aopsjob (gid uuid PRIMARY KEY, name TEXT NOT NULL, created TIMESTAMP NOT NULL, exclusive BOOL NOT NULL, " +
|
||||||
"startafter TIMESTAMP NOT NULL, jobtype INTEGER NOT NULL, subtype INTEGER, objectid BIGINT, objecttype INTEGER, jobstatus INTEGER NOT NULL, jobinfo TEXT)");
|
"startafter TIMESTAMP NOT NULL, jobtype INTEGER NOT NULL, subtype INTEGER, objectid BIGINT, objecttype INTEGER, jobstatus INTEGER NOT NULL, jobinfo TEXT)");
|
||||||
await ExecQueryAsync("CREATE TABLE aopsjoblog (gid uuid PRIMARY KEY, jobid uuid NOT NULL, created TIMESTAMP NOT NULL, statustext TEXT NOT NULL)");
|
await ExecQueryAsync("CREATE TABLE aopsjoblog (gid uuid PRIMARY KEY, jobid uuid NOT NULL, created TIMESTAMP NOT NULL, statustext TEXT NOT NULL)");
|
||||||
// REFERENCES aopsjob (gid) took this out to allow for internal job logs with guid.empty and no parent job as there seems no need anyway
|
|
||||||
await SetSchemaLevelAsync(++currentSchema);
|
await SetSchemaLevelAsync(++currentSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user