This commit is contained in:
2019-03-29 17:05:49 +00:00
parent 431c715890
commit b1d78b9fe5
9 changed files with 80 additions and 80 deletions

View File

@@ -32,7 +32,7 @@ namespace AyaNova.Biz
if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true) if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true)
{ {
//Ok, this field is required but custom fields are all empty so add this error //Ok, this field is required but custom fields are all empty so add this error
biz.AddError(ValidationErrorType.CustomRequiredPropertyEmpty, fldKey); biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, fldKey);
} }
} }
@@ -67,7 +67,7 @@ namespace AyaNova.Biz
var fldRequired = jo["required"].Value<bool>(); var fldRequired = jo["required"].Value<bool>();
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue)) if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
{ {
biz.AddError(ValidationErrorType.CustomRequiredPropertyEmpty, iFldKey); biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
} }
break; break;
} }
@@ -77,7 +77,7 @@ namespace AyaNova.Biz
else else
{ {
//This is a serious issue and invalidates all //This is a serious issue and invalidates all
biz.AddError(ValidationErrorType.RequiredPropertyMissing, iFldKey); biz.AddError(ApiErrorCode.VALIDATION_MISSING_PROPERTY, iFldKey);
} }
} }

View File

@@ -220,20 +220,20 @@ namespace AyaNova.Biz
if (!isNew) if (!isNew)
{ {
if (inObj.OwnerId == 0) if (inObj.OwnerId == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "OwnerId");
} }
// //Owner must be current user, there are no exceptions // //Owner must be current user, there are no exceptions
// if (inObj.OwnerId != UserId) // if (inObj.OwnerId != UserId)
// AddError(ValidationErrorType.InvalidValue, "OwnerId", "OwnerId must be current user Id"); // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "OwnerId", "OwnerId must be current user Id");
//Name required //Name required
if (string.IsNullOrWhiteSpace(inObj.Name)) if (string.IsNullOrWhiteSpace(inObj.Name))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Name"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
//Name must be less than 255 characters //Name must be less than 255 characters
if (inObj.Name.Length > 255) if (inObj.Name.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "Name", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
//If name is otherwise OK, check that name is unique //If name is otherwise OK, check that name is unique
if (!PropertyHasErrors("Name")) if (!PropertyHasErrors("Name"))
@@ -241,21 +241,21 @@ namespace AyaNova.Biz
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (ct.DataFilter.Any(m => m.Name == inObj.Name && m.Id != inObj.Id)) if (ct.DataFilter.Any(m => m.Name == inObj.Name && m.Id != inObj.Id))
{ {
AddError(ValidationErrorType.NotUnique, "Name"); AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
} }
} }
if (string.IsNullOrWhiteSpace(inObj.ListKey)) if (string.IsNullOrWhiteSpace(inObj.ListKey))
AddError(ValidationErrorType.RequiredPropertyEmpty, "ListKey"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListKey");
FilterOptions ListValidFilterOptions = FilterOptionsFromListKey.Get(inObj.ListKey); FilterOptions ListValidFilterOptions = FilterOptionsFromListKey.Get(inObj.ListKey);
if (ListValidFilterOptions == null) if (ListValidFilterOptions == null)
{ {
AddError(ValidationErrorType.InvalidValue, "ListKey", $"ListKey \"{inObj.ListKey}\" is empty or in-valid"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListKey", $"ListKey \"{inObj.ListKey}\" is empty or in-valid");
} }
if (inObj.ListKey.Length > 255) if (inObj.ListKey.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "ListKey", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "ListKey", "255 max");
//Filter json must parse //Filter json must parse
if (!string.IsNullOrWhiteSpace(inObj.Filter)) if (!string.IsNullOrWhiteSpace(inObj.Filter))
@@ -267,12 +267,12 @@ namespace AyaNova.Biz
{ {
var filterItem = v[i]; var filterItem = v[i];
if (filterItem["fld"] == null) if (filterItem["fld"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing required \"fld\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing required \"fld\" property ");
else else
{ {
var fld = filterItem["fld"].Value<string>(); var fld = filterItem["fld"].Value<string>();
if (string.IsNullOrWhiteSpace(fld)) if (string.IsNullOrWhiteSpace(fld))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, \"fld\" property is empty and required"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, \"fld\" property is empty and required");
//validate the field name if we can //validate the field name if we can
if (ListValidFilterOptions != null) if (ListValidFilterOptions != null)
@@ -280,29 +280,29 @@ namespace AyaNova.Biz
if (!ListValidFilterOptions.Flds.Exists(x => x.Fld == fld)) if (!ListValidFilterOptions.Flds.Exists(x => x.Fld == fld))
{ {
AddError(ValidationErrorType.InvalidValue, "Filter", $"Filter array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
} }
} }
} }
if (filterItem["op"] == null) if (filterItem["op"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing required \"op\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing required \"op\" property ");
else else
{ {
var opType = filterItem["op"].Value<string>(); var opType = filterItem["op"].Value<string>();
if (!FilterComparisonOperator.Operators.Contains(opType)) if (!FilterComparisonOperator.Operators.Contains(opType))
AddError(ValidationErrorType.InvalidValue, "Filter", $"Filter array item {i}, \"op\" property value of \"{opType}\" is not a valid FilterComparisonOperator type"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, \"op\" property value of \"{opType}\" is not a valid FilterComparisonOperator type");
} }
if (filterItem["value"] == null) if (filterItem["value"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ");
else else
{ {
if (filterItem["value"].Type == JTokenType.String && string.IsNullOrWhiteSpace(filterItem["value"].Value<string>())) if (filterItem["value"].Type == JTokenType.String && string.IsNullOrWhiteSpace(filterItem["value"].Value<string>()))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ");
if (filterItem["value"].Type == JTokenType.Array && filterItem["value"].Count() == 0) if (filterItem["value"].Type == JTokenType.Array && filterItem["value"].Count() == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ARRAY "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ARRAY ");
} }
@@ -311,7 +311,7 @@ namespace AyaNova.Biz
} }
catch (Newtonsoft.Json.JsonReaderException ex) catch (Newtonsoft.Json.JsonReaderException ex)
{ {
AddError(ValidationErrorType.InvalidValue, "Filter", "Filter is not valid JSON string: " + ex.Message); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", "Filter is not valid JSON string: " + ex.Message);
} }
} }
@@ -328,12 +328,12 @@ namespace AyaNova.Biz
{ {
var sortItem = v[i]; var sortItem = v[i];
if (sortItem["fld"] == null) if (sortItem["fld"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Sort", $"Sort array item {i}, object is missing required \"fld\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"fld\" property ");
else else
{ {
var fld = sortItem["fld"].Value<string>(); var fld = sortItem["fld"].Value<string>();
if (string.IsNullOrWhiteSpace(fld)) if (string.IsNullOrWhiteSpace(fld))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Sort", $"Sort array item {i}, \"fld\" property is empty and required"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, \"fld\" property is empty and required");
//validate the field name if we can //validate the field name if we can
if (ListValidFilterOptions != null) if (ListValidFilterOptions != null)
@@ -341,25 +341,25 @@ namespace AyaNova.Biz
if (!ListValidFilterOptions.Flds.Exists(x => x.Fld == fld)) if (!ListValidFilterOptions.Flds.Exists(x => x.Fld == fld))
{ {
AddError(ValidationErrorType.InvalidValue, "Sort", $"Sort array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
} }
} }
} }
if (sortItem["dir"] == null) if (sortItem["dir"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Sort", $"Sort array item {i}, object is missing required \"dir\" sort direction property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"dir\" sort direction property ");
else else
{ {
var sortDir = sortItem["dir"].Value<string>(); var sortDir = sortItem["dir"].Value<string>();
if (sortDir != "+" && sortDir != "-") if (sortDir != "+" && sortDir != "-")
AddError(ValidationErrorType.InvalidValue, "Sort", $"Sort array item {i}, \"dir\" property value of \"{sortDir}\" is not a valid sort direction value, must be \"+\" or \"-\" only"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, \"dir\" property value of \"{sortDir}\" is not a valid sort direction value, must be \"+\" or \"-\" only");
} }
//NOTE: value of nothing, null or empty is a valid value so no checking for it here //NOTE: value of nothing, null or empty is a valid value so no checking for it here
} }
} }
catch (Newtonsoft.Json.JsonReaderException ex) catch (Newtonsoft.Json.JsonReaderException ex)
{ {
AddError(ValidationErrorType.InvalidValue, "Sort", "Sort is not valid JSON string: " + ex.Message); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", "Sort is not valid JSON string: " + ex.Message);
} }
} }

View File

@@ -142,27 +142,27 @@ namespace AyaNova.Biz
if (!isNew) if (!isNew)
{ {
if (inObj.OwnerId == 0) if (inObj.OwnerId == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "OwnerId");
} }
// //Owner must be current user, there are no exceptions // //Owner must be current user, there are no exceptions
// if (inObj.OwnerId != UserId) // if (inObj.OwnerId != UserId)
// AddError(ValidationErrorType.InvalidValue, "OwnerId", "OwnerId must be current user Id"); // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "OwnerId", "OwnerId must be current user Id");
//FormKey required and must be valid //FormKey required and must be valid
if (string.IsNullOrWhiteSpace(inObj.FormKey)) if (string.IsNullOrWhiteSpace(inObj.FormKey))
AddError(ValidationErrorType.RequiredPropertyEmpty, "FormKey"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "FormKey");
else else
{ {
if (!FormAvailableFields.IsValidFormKey(inObj.FormKey)) if (!FormAvailableFields.IsValidFormKey(inObj.FormKey))
{ {
AddError(ValidationErrorType.InvalidValue, "FormKey"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "FormKey");
} }
} }
//FormKey must be less than 255 characters //FormKey must be less than 255 characters
if (inObj.FormKey.Length > 255) if (inObj.FormKey.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "FormKey", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "FormKey", "255 max");
//If name is otherwise OK, check that name is unique //If name is otherwise OK, check that name is unique
if (!PropertyHasErrors("FormKey") && isNew) if (!PropertyHasErrors("FormKey") && isNew)
@@ -170,7 +170,7 @@ namespace AyaNova.Biz
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (ct.FormCustom.Any(m => m.FormKey == inObj.FormKey && m.Id != inObj.Id)) if (ct.FormCustom.Any(m => m.FormKey == inObj.FormKey && m.Id != inObj.Id))
{ {
AddError(ValidationErrorType.NotUnique, "FormKey"); AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "FormKey");
} }
} }
@@ -192,12 +192,12 @@ namespace AyaNova.Biz
var formFieldItem = v[i]; var formFieldItem = v[i];
if (formFieldItem["fld"] == null) if (formFieldItem["fld"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Template", $"Template array item {i}, object is missing required \"fld\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Template", $"Template array item {i}, object is missing required \"fld\" property ");
else else
{ {
var fldKey = formFieldItem["fld"].Value<string>(); var fldKey = formFieldItem["fld"].Value<string>();
if (string.IsNullOrWhiteSpace(fldKey)) if (string.IsNullOrWhiteSpace(fldKey))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Template", $"Template array item {i}, \"fld\" property is empty and required"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Template", $"Template array item {i}, \"fld\" property is empty and required");
//validate the field name if we can //validate the field name if we can
if (ValidFormFields != null) if (ValidFormFields != null)
@@ -205,7 +205,7 @@ namespace AyaNova.Biz
if (!ValidFormFields.Exists(x => x.Key == fldKey)) if (!ValidFormFields.Exists(x => x.Key == fldKey))
{ {
AddError(ValidationErrorType.InvalidValue, "Template", $"Template array item {i}, fld property value \"{fldKey}\" is not a valid form field value for formKey specified"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", $"Template array item {i}, fld property value \"{fldKey}\" is not a valid form field value for formKey specified");
} }
else else
{ {
@@ -223,25 +223,25 @@ namespace AyaNova.Biz
{ {
var fieldHideValue = formFieldItem["hide"].Value<bool>(); var fieldHideValue = formFieldItem["hide"].Value<bool>();
if (!MasterFormField.Hideable && fieldHideValue == true) if (!MasterFormField.Hideable && fieldHideValue == true)
AddError(ValidationErrorType.InvalidValue, "Template", $"Template array item {i}, \"hide\" property value of \"{fieldHideValue}\" is not valid, this field is core and cannot be hidden"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", $"Template array item {i}, \"hide\" property value of \"{fieldHideValue}\" is not valid, this field is core and cannot be hidden");
} }
if (formFieldItem["type"] != null) if (formFieldItem["type"] != null)
{ {
if (!MasterFormField.Custom) if (!MasterFormField.Custom)
AddError(ValidationErrorType.InvalidValue, "Template", $"Template array item {i}, \"type\" property value is not valid, only Custom fields can have types specified"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", $"Template array item {i}, \"type\" property value is not valid, only Custom fields can have types specified");
else else
{//It is a custom field, is it a valid type value {//It is a custom field, is it a valid type value
var templateFieldCustomTypeValue = formFieldItem["type"].Value<string>(); var templateFieldCustomTypeValue = formFieldItem["type"].Value<string>();
if (!ValidCustomFieldTypes.Contains(templateFieldCustomTypeValue)) if (!ValidCustomFieldTypes.Contains(templateFieldCustomTypeValue))
AddError(ValidationErrorType.InvalidValue, "Template", $"Template array item {i}, \"type\" property value of \"{templateFieldCustomTypeValue}\" is not a valid custom field type"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", $"Template array item {i}, \"type\" property value of \"{templateFieldCustomTypeValue}\" is not a valid custom field type");
} }
} }
} }
if (formFieldItem["required"] == null) if (formFieldItem["required"] == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "Template", $"Template array item {i}, object is missing required \"required\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Template", $"Template array item {i}, object is missing required \"required\" property ");
//NOTE: value of nothing, null or empty is a valid value so no checking for it here //NOTE: value of nothing, null or empty is a valid value so no checking for it here
@@ -249,7 +249,7 @@ namespace AyaNova.Biz
} }
catch (Newtonsoft.Json.JsonReaderException ex) catch (Newtonsoft.Json.JsonReaderException ex)
{ {
AddError(ValidationErrorType.InvalidValue, "Template", "Template is not valid JSON string: " + ex.Message); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", "Template is not valid JSON string: " + ex.Message);
} }
} }

View File

@@ -51,7 +51,7 @@ namespace AyaNova.Biz
//make sure sourceid exists //make sure sourceid exists
if (!LocaleExists(inObj.Id)) if (!LocaleExists(inObj.Id))
AddError(ValidationErrorType.InvalidValue, "Id", "Source locale id does not exist"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Id", "Source locale id does not exist");
//Ensure name is unique and not too long and not empty //Ensure name is unique and not too long and not empty
Validate(inObj.Name, true); Validate(inObj.Name, true);
@@ -222,7 +222,7 @@ namespace AyaNova.Biz
if (dbParent.Stock == true) if (dbParent.Stock == true)
{ {
AddError(ValidationErrorType.InvalidOperation, "object", "LocaleItem is from a Stock locale and cannot be modified"); AddError(ApiErrorCode.INVALID_OPERATION, "object", "LocaleItem is from a Stock locale and cannot be modified");
return false; return false;
} }
@@ -235,7 +235,7 @@ namespace AyaNova.Biz
//Only thing to validate is if it has data at all in it //Only thing to validate is if it has data at all in it
if (string.IsNullOrWhiteSpace(inObj.NewText)) if (string.IsNullOrWhiteSpace(inObj.NewText))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Display (NewText)"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Display (NewText)");
if (HasErrors) if (HasErrors)
return false; return false;
@@ -252,7 +252,7 @@ namespace AyaNova.Biz
{ {
if (dbObj.Stock == true) if (dbObj.Stock == true)
{ {
AddError(ValidationErrorType.InvalidOperation, "object", "Locale is a Stock locale and cannot be modified"); AddError(ApiErrorCode.INVALID_OPERATION, "object", "Locale is a Stock locale and cannot be modified");
return false; return false;
} }
@@ -303,15 +303,15 @@ namespace AyaNova.Biz
//Name required //Name required
if (string.IsNullOrWhiteSpace(inObjName)) if (string.IsNullOrWhiteSpace(inObjName))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Name"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
//Name must be less than 255 characters //Name must be less than 255 characters
if (inObjName.Length > 255) if (inObjName.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "Name", "255 char max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 char max");
//Name must be unique //Name must be unique
if (ct.Locale.Where(m => m.Name == inObjName).FirstOrDefault() != null) if (ct.Locale.Where(m => m.Name == inObjName).FirstOrDefault() != null)
AddError(ValidationErrorType.NotUnique, "Name"); AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
return; return;
} }
@@ -325,20 +325,20 @@ namespace AyaNova.Biz
//Ensure it's not a stock locale //Ensure it's not a stock locale
if (inObj.Stock == true) if (inObj.Stock == true)
{ {
AddError(ValidationErrorType.InvalidOperation, "object", "Locale is a Stock locale and cannot be deleted"); AddError(ApiErrorCode.INVALID_OPERATION, "object", "Locale is a Stock locale and cannot be deleted");
return; return;
} }
if (inObj.Id == ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID) if (inObj.Id == ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID)
{ {
AddError(ValidationErrorType.InvalidOperation, "object", "Locale is set as the default server locale (AYANOVA_DEFAULT_LANGUAGE_ID) and can not be deleted"); AddError(ApiErrorCode.INVALID_OPERATION, "object", "Locale is set as the default server locale (AYANOVA_DEFAULT_LANGUAGE_ID) and can not be deleted");
return; return;
} }
//See if any users exist with this locale selected in which case it's not deleteable //See if any users exist with this locale selected in which case it's not deleteable
if (ct.User.Any(e => e.LocaleId == inObj.Id)) if (ct.User.Any(e => e.LocaleId == inObj.Id))
{ {
AddError(ValidationErrorType.ReferentialIntegrity, "object", "Can't be deleted in use by one or more Users"); AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "object", "Can't be deleted in use by one or more Users");
return; return;
} }
} }

View File

@@ -38,7 +38,7 @@ namespace AyaNova.Biz
object propertyValue = proposedObject.GetType().GetProperty(RequiredPropertyName).GetValue(proposedObject, null); object propertyValue = proposedObject.GetType().GetProperty(RequiredPropertyName).GetValue(proposedObject, null);
if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString())) if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString()))
biz.AddError(ValidationErrorType.RequiredPropertyEmpty, FldLtKey); biz.AddError(ApiErrorCode.VALIDATION_REQUIRED, FldLtKey);
} }
} }

View File

@@ -416,16 +416,16 @@ namespace AyaNova.Biz
if (!isNew) if (!isNew)
{ {
if (proposedObj.OwnerId == 0) if (proposedObj.OwnerId == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "OwnerId");
} }
//Name required //Name required
if (string.IsNullOrWhiteSpace(proposedObj.Name)) if (string.IsNullOrWhiteSpace(proposedObj.Name))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Name"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
//Name must be less than 255 characters //Name must be less than 255 characters
if (proposedObj.Name.Length > 255) if (proposedObj.Name.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "Name", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
//If name is otherwise OK, check that name is unique //If name is otherwise OK, check that name is unique
if (!PropertyHasErrors("Name")) if (!PropertyHasErrors("Name"))
@@ -433,7 +433,7 @@ namespace AyaNova.Biz
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (ct.User.Any(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id)) if (ct.User.Any(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
{ {
AddError(ValidationErrorType.NotUnique, "Name"); AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
} }
} }
@@ -467,7 +467,7 @@ namespace AyaNova.Biz
if (!proposedObj.UserType.IsValid()) if (!proposedObj.UserType.IsValid())
{ {
AddError(ValidationErrorType.InvalidValue, "UserType"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType");
} }
//Validate client type user //Validate client type user
@@ -475,7 +475,7 @@ namespace AyaNova.Biz
{ {
if (proposedObj.ClientId == null || proposedObj.ClientId == 0) if (proposedObj.ClientId == null || proposedObj.ClientId == 0)
{ {
AddError(ValidationErrorType.RequiredPropertyEmpty, "ClientId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "ClientId");
} }
else else
{ {
@@ -489,7 +489,7 @@ namespace AyaNova.Biz
{ {
if (proposedObj.HeadOfficeId == null || proposedObj.HeadOfficeId == 0) if (proposedObj.HeadOfficeId == null || proposedObj.HeadOfficeId == 0)
{ {
AddError(ValidationErrorType.RequiredPropertyEmpty, "HeadOfficeId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "HeadOfficeId");
} }
else else
{ {
@@ -503,7 +503,7 @@ namespace AyaNova.Biz
{ {
if (proposedObj.SubVendorId == null || proposedObj.SubVendorId == 0) if (proposedObj.SubVendorId == null || proposedObj.SubVendorId == 0)
{ {
AddError(ValidationErrorType.RequiredPropertyEmpty, "SubVendorId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "SubVendorId");
} }
else else
{ {
@@ -514,12 +514,12 @@ namespace AyaNova.Biz
if (!proposedObj.Roles.IsValid()) if (!proposedObj.Roles.IsValid())
{ {
AddError(ValidationErrorType.InvalidValue, "Roles"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Roles");
} }
//Optional employee number field must be less than 255 characters //Optional employee number field must be less than 255 characters
if (!string.IsNullOrWhiteSpace(proposedObj.EmployeeNumber) && proposedObj.EmployeeNumber.Length > 255) if (!string.IsNullOrWhiteSpace(proposedObj.EmployeeNumber) && proposedObj.EmployeeNumber.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "EmployeeNumber", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "EmployeeNumber", "255 max");
//Any form customizations to validate? //Any form customizations to validate?
var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == FormAvailableFields.USER_FORM_KEY); var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == FormAvailableFields.USER_FORM_KEY);
@@ -541,7 +541,7 @@ namespace AyaNova.Biz
{ {
if (CurrentActiveCount >= LicensedUserCount) if (CurrentActiveCount >= LicensedUserCount)
{ {
AddError(ValidationErrorType.InvalidOperation, null, "LT:ErrorSecurityUserCapacity"); AddError(ApiErrorCode.INVALID_OPERATION, null, "LT:ErrorSecurityUserCapacity");
} }
} }
@@ -562,7 +562,7 @@ namespace AyaNova.Biz
//There's only one rule - have they done anything eventlog worthy yet? //There's only one rule - have they done anything eventlog worthy yet?
if (ct.Event.Select(m => m).Where(m => m.OwnerId == inObj.Id).Count() > 0) if (ct.Event.Select(m => m).Where(m => m.OwnerId == inObj.Id).Count() > 0)
{ {
AddError(ValidationErrorType.InvalidOperation, "user", "LT:ErrorDBForeignKeyViolation"); AddError(ApiErrorCode.INVALID_OPERATION, "user", "LT:ErrorDBForeignKeyViolation");
return; return;
} }

View File

@@ -100,11 +100,11 @@ namespace AyaNova.Biz
//OwnerId required //OwnerId required
if (inObj.OwnerId == 0) if (inObj.OwnerId == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "OwnerId");
//OwnerId required //OwnerId required
if (inObj.UserId == 0) if (inObj.UserId == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "UserId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "UserId");
//LOOKAT:Validate email address is legitimate (I put the EMailAddress attribute on the field in the model so I think it might validate) //LOOKAT:Validate email address is legitimate (I put the EMailAddress attribute on the field in the model so I think it might validate)

View File

@@ -25,7 +25,7 @@ namespace AyaNova.Biz
{ {
if (objectPatch.Operations.Any(m => m.path == $"/{Property.ToLowerInvariant()}")) if (objectPatch.Operations.Any(m => m.path == $"/{Property.ToLowerInvariant()}"))
{ {
biz.AddError(ValidationErrorType.NotChangeable, Property); biz.AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, Property);
IsValid = false; IsValid = false;
} }
} }
@@ -33,31 +33,31 @@ namespace AyaNova.Biz
//check for in-valid patches //check for in-valid patches
if (objectPatch.Operations.Any(m => m.path == "/id")) if (objectPatch.Operations.Any(m => m.path == "/id"))
{ {
biz.AddError(ValidationErrorType.NotChangeable, "Id"); biz.AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "Id");
IsValid = false; IsValid = false;
} }
if (objectPatch.Operations.Any(m => m.path == "/ownerid")) if (objectPatch.Operations.Any(m => m.path == "/ownerid"))
{ {
biz.AddError(ValidationErrorType.NotChangeable, "OwnerId"); biz.AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "OwnerId");
IsValid = false; IsValid = false;
} }
if (objectPatch.Operations.Any(m => m.path == "/serial")) if (objectPatch.Operations.Any(m => m.path == "/serial"))
{ {
biz.AddError(ValidationErrorType.NotChangeable, "Serial"); biz.AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "Serial");
IsValid = false; IsValid = false;
} }
if (objectPatch.Operations.Any(m => m.op == "add")) if (objectPatch.Operations.Any(m => m.op == "add"))
{ {
biz.AddError(ValidationErrorType.InvalidOperation, "add"); biz.AddError(ApiErrorCode.INVALID_OPERATION, "add");
IsValid = false; IsValid = false;
} }
if (objectPatch.Operations.Any(m => m.op == "remove")) if (objectPatch.Operations.Any(m => m.op == "remove"))
{ {
biz.AddError(ValidationErrorType.InvalidOperation, "remove"); biz.AddError(ApiErrorCode.INVALID_OPERATION, "remove");
IsValid = false; IsValid = false;
} }

View File

@@ -351,7 +351,7 @@ namespace AyaNova.Biz
// // //NEW widgets must be active // // //NEW widgets must be active
// // if (inObj.Active == null || ((bool)inObj.Active) == false) // // if (inObj.Active == null || ((bool)inObj.Active) == false)
// // { // // {
// // AddError(ValidationErrorType.InvalidValue, "Active", "New widget must be active"); // // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Active", "New widget must be active");
// // } // // }
// } // }
@@ -359,16 +359,16 @@ namespace AyaNova.Biz
if (!isNew) if (!isNew)
{ {
if (proposedObj.OwnerId == 0) if (proposedObj.OwnerId == 0)
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "OwnerId");
} }
//Name required //Name required
if (string.IsNullOrWhiteSpace(proposedObj.Name)) if (string.IsNullOrWhiteSpace(proposedObj.Name))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Name"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
//Name must be less than 255 characters //Name must be less than 255 characters
if (proposedObj.Name.Length > 255) if (proposedObj.Name.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "Name", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
//If name is otherwise OK, check that name is unique //If name is otherwise OK, check that name is unique
if (!PropertyHasErrors("Name")) if (!PropertyHasErrors("Name"))
@@ -376,27 +376,27 @@ namespace AyaNova.Biz
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (ct.Widget.Any(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id)) if (ct.Widget.Any(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
{ {
AddError(ValidationErrorType.NotUnique, "Name"); AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
} }
} }
//Start date AND end date must both be null or both contain values //Start date AND end date must both be null or both contain values
if (proposedObj.StartDate == null && proposedObj.EndDate != null) if (proposedObj.StartDate == null && proposedObj.EndDate != null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "StartDate"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate");
if (proposedObj.StartDate != null && proposedObj.EndDate == null) if (proposedObj.StartDate != null && proposedObj.EndDate == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "EndDate"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate");
//Start date before end date //Start date before end date
if (proposedObj.StartDate != null && proposedObj.EndDate != null) if (proposedObj.StartDate != null && proposedObj.EndDate != null)
if (proposedObj.StartDate > proposedObj.EndDate) if (proposedObj.StartDate > proposedObj.EndDate)
AddError(ValidationErrorType.StartDateMustComeBeforeEndDate, "StartDate"); AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate");
//Enum is valid value //Enum is valid value
if (!proposedObj.Roles.IsValid()) if (!proposedObj.Roles.IsValid())
{ {
AddError(ValidationErrorType.InvalidValue, "Roles"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Roles");
} }
//Any form customizations to validate? //Any form customizations to validate?