Beispiel #1
0
        private void ValidateQuestion(Question question, List <KeyValuePair <string, string> > validationErrors, Answer answerToThisQuestion)
        {
            var validators = _validatorFactory.Build(question);

            if (answerToThisQuestion is null || question.Input.GetEmptyAnswerValues().Contains(answerToThisQuestion.Value))
            {
                if (!validators.Any(v => v.GetType().Name.EndsWith("RequiredValidator")))
                {
                    return;
                }

                var requiredValidators = validators.Where(v => v.GetType().Name.EndsWith("RequiredValidator"));
                foreach (var requiredValidator in requiredValidators)
                {
                    var errors = requiredValidator.Validate(question, answerToThisQuestion);
                    if (errors.Any())
                    {
                        validationErrors.AddRange(errors);
                    }
                }
            }