Example #1
0
        internal static void ParseAndValidate(
            GovUkViewModel model,
            PropertyInfo property,
            HttpRequest httpRequest)
        {
            string       propertyName    = $"GovUk_Radio_{property.Name}";
            StringValues parameterValues = httpRequest.Form[propertyName];

            ThrowIfPropertyTypeIsNotNullableEnum(property);
            ParserHelpers.ThrowIfMoreThanOneValue(parameterValues, property);

            if (ParserHelpers.IsValueRequiredAndMissing(property, parameterValues))
            {
                ParserHelpers.AddRequiredAndMissingErrorMessage(model, property);
                return;
            }

            if (parameterValues.Count > 0)
            {
                string parameterValueAsString = parameterValues[0];

                object parameterAsEnum = ParseParameterAsEnum(parameterValueAsString, property);

                property.SetValue(model, parameterAsEnum);
            }

            model.ValueWasSuccessfullyParsed(property);
        }