Esempio n. 1
0
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            var modelName = bindingContext.ModelName;

            var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);

            if (valueProviderResult == ValueProviderResult.None)
            {
                return(Task.CompletedTask);
            }

            bindingContext.ModelState.SetModelValue(modelName, valueProviderResult);

            var value = valueProviderResult.FirstValue;

            if (string.IsNullOrWhiteSpace(value))
            {
                return(Task.CompletedTask);
            }

            var errorMessage = CuitNumber.ValidateNumber(value);

            if (errorMessage != null)
            {
                bindingContext.ModelState.TryAddModelError(
                    modelName,
                    errorMessage.ErrorMessage);
                return(Task.CompletedTask);
            }

            bindingContext.Result = ModelBindingResult.Success(new CuitNumber(value));
            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            var stringValue = value as string;

            return(CuitNumber.ValidateNumber(stringValue) == ValidationResult.Success);
        }
Esempio n. 3
0
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 => CuitNumber.ValidateNumber(value as string);