This commit is contained in:
2019-06-25 19:41:32 +00:00
parent 983f95cf7c
commit 04bd831a4d
5 changed files with 54 additions and 31 deletions

View File

@@ -23,7 +23,7 @@ Here are all the API level error codes that can be returned by the API server:
| 2201 | Validation error - Field is required but is empty or null |
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |
| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) |
| 2204 | Validation error - Customized form property set to required has an empty value |
| 2204 | Validation error - Customized form property is set to required but has an empty value |
| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error |
| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database |
| 2207 | Validation error - The start date must be earlier than the end date |

View File

@@ -50,7 +50,7 @@ namespace AyaNova.Biz
| 2201 | Validation error - Field is required but is empty or null |
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |
| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) |
| 2204 | Validation error - Customized form property set to required has an empty value |
| 2204 | Validation error - Customized form property is set to required but has an empty value |
| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error |
| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database |
| 2207 | Validation error - When an object requires a start and end date the start date must be earlier than the end date |

View File

@@ -43,7 +43,7 @@ namespace AyaNova.Biz
case ApiErrorCode.VALIDATION_INVALID_VALUE:
return "Field is set to a non allowed value";
case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY:
return "Customized form property set to required has an empty value";
return "Customized form property is set to required but has an empty value";
case ApiErrorCode.VALIDATION_MISSING_PROPERTY:
return "Required property is missing entirel";
case ApiErrorCode.VALIDATION_NOT_UNIQUE:

View File

@@ -16,9 +16,9 @@ namespace AyaNova.Biz
return;
var OuterJson=JObject.Parse(formCustom.Template);
var OuterJson = JObject.Parse(formCustom.Template);
//var FormTemplate = JArray.Parse(formCustom.Template);
var FormTemplate=(JArray)OuterJson["template"];
var FormTemplate = (JArray)OuterJson["template"];
var ThisFormCustomFieldsList = FormAvailableFields.FormFields(formCustom.FormKey).Where(x => x.Custom == true).Select(x => x.Key).ToList();
//If the customFields string is empty then only validation is if any of the fields are required to be filled in
@@ -48,12 +48,21 @@ namespace AyaNova.Biz
//However the LT field names might be WidgetCustom1 or UserCustom16 so we need to translate by EndsWith
var CustomFieldData = JObject.Parse(customFields);
//make sure all the keys are present
//make sure all the *required* keys are present
foreach (string iFldKey in ThisFormCustomFieldsList)
{
//Now translate the LT field key to the actual customFieldData field key
var InternalCustomFieldName=FormAvailableFields.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
//Translate the LT field key to the actual customFieldData field key
var InternalCustomFieldName = FormAvailableFields.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
//Check if it's set to required
var isRequired = CustomFieldIsSetToRequired(FormTemplate, iFldKey);
//if it's not required then we don't care, jump to the next item...
if (!isRequired)
continue;
//It's required, make sure the key is present and contains data
if (CustomFieldData.ContainsKey(InternalCustomFieldName))
{
//validate for now that the custom fields set as required have data in them. Note that we are not validating the sanity of the values, only that they exist
@@ -62,18 +71,24 @@ namespace AyaNova.Biz
//validate it
string CurrentValue = CustomFieldData[InternalCustomFieldName].Value<string>();
foreach (JObject jo in FormTemplate)
{
if (jo["fld"].Value<string>() == iFldKey)
{
var fldRequired = jo["required"].Value<bool>();
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
if (string.IsNullOrWhiteSpace(CurrentValue))
{
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
}
break;
}
}
// foreach (JObject jo in FormTemplate)
// {
// if (jo["fld"].Value<string>() == iFldKey)
// {
// var fldRequired = jo["required"].Value<bool>();
// if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
// {
// biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
// }
// break;
// }
// }
}
else
@@ -85,5 +100,23 @@ namespace AyaNova.Biz
}
/// <summary>
/// Check if field is required
/// </summary>
/// <param name="FormTemplate"></param>
/// <param name="FieldKey"></param>
/// <returns></returns>
private static bool CustomFieldIsSetToRequired(JArray FormTemplate, string FieldKey)
{
foreach (JObject jo in FormTemplate)
{
if (jo["fld"].Value<string>() == FieldKey)
{
return jo["required"].Value<bool>();
}
}
return false;
}
}//eoc
}//ens

View File

@@ -527,18 +527,8 @@ namespace AyaNova.Util
o.Notes = f.Lorem.Paragraph();
o.Tags = RandomTags(f);
//RANDOM CUSTOM FIELD DATA
//var custDate=GetSomeDateHereThatIsThenMadeIntoText;
// Template = "{template:[{fld:\"WidgetNotes\",required:\"true\"}" +
// ",{fld:\"WidgetCustom1\",hide:\"false\",required:\"false\", type:\"date\"}" +
// ",{fld:\"WidgetCustom2\",hide:\"false\",required:\"true\", type:\"text\"}" +
// ",{fld:\"WidgetCustom3\",hide:\"false\",required:\"false\", type:\"int\"}" +
// ",{fld:\"WidgetCustom4\",hide:\"false\",required:\"false\", type:\"bool\"}" +
// ",{fld:\"WidgetCustom5\",hide:\"false\",required:\"false\", type:\"decimal\"}" +
// "]"
o.CustomFields=@"{c1:""2019-05-01T21:38:07Z"",c2:""Here is some custom field text in position 2"",c3:100,c4:true,c5:5.55}";
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, o);