Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Dependent Validations

$
0
0

How can I define a Rule for the following scenario:

The customer has a property - customerType, and according to that, there must be a validation to check if the home country he picked is in a lista of values.

 

I've tried the following:

 

RuleFor(customer => customer.HomeCountry).NotEmpty().Must(IsValidCountryCategory(customerType, homeCountryCategory)).WithMessage("Select a valid country");

private bool IsValidCountryCategory(string customerType, string homeCountryCategory)
        {
            var ValidCountries = new List<string>();

            //categorias v�lidas para clientes do tipo R
            ValidCountries.Add("B");
            ValidCountries.Add("E");
            ValidCountries.Add("O");
            ValidCountries.Add("P");

            return ValidCountries.Contains(homeCountryCategory);
        }

 

But in the rule definition, i'm getting the following error:

'FluentValidation.IRuleBuilderOptions<ConsoleApplication1.Customer,string>' does not contain a definition for 'Must' and the best extension method overload 'FluentValidation.DefaultValidatorExtensions.Must<T,TProperty>(FluentValidation.IRuleBuilder<T,TProperty>, System.Func<T,TProperty,FluentValidation.Validators.PropertyValidatorContext,bool>)' has some invalid arguments  

 

Can you help me ? waht am I doing wrong ?

 

Best regards.


Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>