Exemple #1
0
        internal override FieldValidationResult Validate(string value, FieldValidationContext context)
        {
            var dependeeAnswer = context.Application.Applicants[0].TradingExperiences.SingleOrDefault(te => te.Alias == DependeeFieldAlias);

            if (dependeeAnswer == null)
            {
                return(null);
            }

            var dependeeFieldValue = DependeeFieldValues.SingleOrDefault(dfv => dfv.Value == dependeeAnswer.Value);

            if (dependeeFieldValue == null)
            {
                if (string.IsNullOrEmpty(value))
                {
                    return(new FieldValidationResult
                    {
                        ErrorMessage = "The field is required."
                    });
                }

                return(null);
            }

            if (!dependeeFieldValue.AnswerSubsetAllowed.Contains(value))
            {
                return(new FieldValidationResult
                {
                    ErrorMessage = $"The field is required but only the following answers are allowed: {string.Join(", ", dependeeFieldValue.AnswerSubsetAllowed)}"
                });
            }

            return(null);
        }
Exemple #2
0
        internal override FieldValidationResult ValidateIfSpecified(string value, FieldValidationContext context)
        {
            if (!Regex.IsMatch(value, Pattern, RegexOptions.IgnoreCase))
            {
                return(new FieldValidationResult
                {
                    ErrorMessage = $"The field {context.Field.Type} does not match the pattern {Pattern}"
                });
            }

            return(null);
        }
Exemple #3
0
        public override FieldValidationResult Validate(object value, FieldValidationContext context)
        {
            if (value == null)
            {
                return(new FieldValidationResult
                {
                    ErrorMessage = "The field is required."
                });
            }

            var valueAsList = value as List <string>;

            if (valueAsList != null)
            {
                if (valueAsList.Count == 0)
                {
                    return(new FieldValidationResult
                    {
                        ErrorMessage = "The field is required."
                    });
                }

                return(null);
            }

            if (value is bool)
            {
                if (!(bool)value)
                {
                    return(new FieldValidationResult
                    {
                        ErrorMessage = "The field is required."
                    });
                }

                return(null);
            }

            var valueAsString = value as string;

            if (string.IsNullOrEmpty(valueAsString))
            {
                return(new FieldValidationResult
                {
                    ErrorMessage = "The field is required."
                });
            }

            return(null);
        }
Exemple #4
0
 public override FieldValidationResult Validate(object value, FieldValidationContext context)
 {
     return(Validate((string)value, context));
 }
Exemple #5
0
 public abstract FieldValidationResult Validate(object value, FieldValidationContext context);