This commit is contained in:
2020-12-29 21:55:49 +00:00
parent 67a2308628
commit 68aeb5c66a
3 changed files with 50 additions and 28 deletions

View File

@@ -113,23 +113,45 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
/*
"CONSTRAINT CHK_Servicebank_Valid_IncidentBalance CHECK(incidentsbalance >= 0 AND (incidentsbalance = COALESCE(lastincidentsbalance, 0) + incidents)), " +
"CONSTRAINT CHK_Servicebank_Valid_CurrencyBalance CHECK(currencybalance >= 0 AND (currencybalance = COALESCE(lastcurrencybalance, 0) + currency)), " +
"CONSTRAINT CHK_Servicebank_Valid_HoursBalance CHECK(hoursbalance >= 0 AND (hoursbalance = COALESCE(lasthoursbalance, 0) + hours)), " +
"CONSTRAINT UNQ_ServiceBank UNIQUE (entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), " +
"CONSTRAINT UNQ_ServiceBank_Previous_values UNIQUE (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance), " +
"CONSTRAINT fk_ServiceBank_self FOREIGN KEY (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance) references aservicebank(entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), " +
"CONSTRAINT CHK_Servicebank_Valid_IncidentBalance CHECK(incidentsbalance = COALESCE(lastincidentsbalance, 0) + incidents), " +
"CONSTRAINT CHK_Servicebank_Valid_CurrencyBalance CHECK(currencybalance = COALESCE(lastcurrencybalance, 0) + currency), " +
"CONSTRAINT CHK_Servicebank_Valid_HoursBalance CHECK(hoursbalance = COALESCE(lasthoursbalance, 0) + hours), " +
"CONSTRAINT CHK_ServiceBank_Valid_Dates_Sequence CHECK(lastentrydate < entrydate), " +
"CONSTRAINT CHK_ServiceBank_Valid_Previous_Columns CHECK((lastentrydate IS NULL AND lastincidentsbalance IS NULL AND lastcurrencybalance IS NULL AND lasthoursbalance IS NULL) OR (lastentrydate IS NOT NULL AND lastincidentsbalance IS NOT NULL AND lastcurrencybalance IS NOT NULL AND lasthoursbalance IS NOT NULL)) "+
*/
//New entry must have *something* to bank
if(proposedObj.Incidents==0 && proposedObj.Hours==0 && proposedObj.Currency==0){
AddError(ApiErrorCode.INVALID_OPERATION,null,"")
}
if (!(
(proposedObj.IncidentsBalance >= 0)
&& (proposedObj.IncidentsBalance== proposedObj.LastIncidentsBalance + proposedObj.Incidents)))
//New entry must have *something* to bank
if (proposedObj.Incidents == 0 && proposedObj.Hours == 0 && proposedObj.Currency == 0)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE);
AddError(ApiErrorCode.INVALID_OPERATION, null, "Nothing to bank");
return;
}
//values must add up
if (proposedObj.IncidentsBalance != proposedObj.LastIncidentsBalance + proposedObj.Incidents)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankIncidentsBalance");
return;
}
if (proposedObj.CurrencyBalance != proposedObj.LastCurrencyBalance + proposedObj.Currency)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankCurrencyBalance");
return;
}
if (proposedObj.HoursBalance != proposedObj.LastHoursBalance + proposedObj.Hours)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:ServiceBankHoursBalance");
return;
}
//date is newer than last entry date?
if (proposedObj.LastEntryDate != null && proposedObj.LastEntryDate > proposedObj.EntryDate)
{
AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "generalerror", "LastEntryDate is newer than EntryDate");
return;
}