public static bool TryGetVoterStatus(this ModelBindingContext bindingContext, string name, ref bool hasValue, out int?result)
        {
            result = null;
            var valueObject = bindingContext.ValueProvider.GetValue(name);

            if (valueObject != ValueProviderResult.None)
            {
                bindingContext.ModelState.SetModelValue(name, valueObject);
                if (!string.IsNullOrEmpty(valueObject.FirstValue))
                {
                    if (!VoterStatuses.TryParse(valueObject.FirstValue, out var status))
                    {
                        bindingContext.ModelState.TryAddModelError(name, "Invalid voter status.");
                        return(false);
                    }
                    hasValue = true;
                    result   = status;
                }
            }

            return(true);
        }
        public static bool TryGetVoterStatusList(this ModelBindingContext bindingContext, string name, ref bool hasValue, out List <int> result)
        {
            result = null;
            var valueObject = bindingContext.ValueProvider.GetValue(name);

            if (valueObject != ValueProviderResult.None)
            {
                bindingContext.ModelState.SetModelValue(name, valueObject);
                if (!string.IsNullOrEmpty(valueObject.FirstValue))
                {
                    var rawValues = valueObject.FirstValue.Split(',', StringSplitOptions.RemoveEmptyEntries);

                    if (rawValues.Length == 0)
                    {
                        bindingContext.ModelState.TryAddModelError(name, "List should contain at least one item.");
                        return(false);
                    }

                    hasValue = true;
                    result   = new List <int>(rawValues.Length);

                    foreach (var rawValue in rawValues)
                    {
                        if (!VoterStatuses.TryParse(rawValue, out var status))
                        {
                            bindingContext.ModelState.TryAddModelError(name, "List contains invalid voter status.");
                            return(false);
                        }
                        hasValue = true;
                        result.Add(status);
                    }
                }
            }

            return(true);
        }