This commit is contained in:
2019-01-15 22:45:40 +00:00
parent 72c2b8f4a5
commit 09609bf1bb
9 changed files with 113 additions and 15 deletions

View File

@@ -0,0 +1,50 @@
using AyaNova.Models;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace AyaNova.Biz
{
internal static class CustomFieldsValidator
{
internal static void Validate(BizObject biz, FormCustom formCustom, string customFields)
{
bool hasCustomData = !string.IsNullOrWhiteSpace(customFields);
//No form custom = no template to check against so nothing to do
if (formCustom == null)
return;
var FormTemplate = JArray.Parse(formCustom.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
if (!hasCustomData)
{
//iterate the template
for (int i = 0; i < FormTemplate.Count; i++)
{
//get the field customization
var fldKey = FormTemplate["fld"].Value<string>();
var fldRequired = FormTemplate["required"].Value<bool>();
//Check if this is an expected custom field and that it was set to required
if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true)
{
//Ok, this field is required but custom fields are all empty so add this error
biz.AddError(ValidationErrorType.RequiredPropertyEmpty, fldKey);
}
}
return;
}
//here we have both a bunch of custom fields presumeably and a form customization so let's get cracking...
var CustomFieldData = JObject.Parse(customFields);
}
}
}