Validation rules

Validation rules

Old forum URL: forums.lhotka.net/forums/t/11058.aspx


San posted on Friday, January 13, 2012

Hi,

There is a validation logic that should check for both conditions. if check 1 failed  it should also check for check 2 but in this case if check 1 failed it is not executing check 2 but i need to check for both conditions though. Any idea's how to solve this problem.

 

    private static bool xyzValidation<T>(T target, RuleArgs e) where T : classname

    {

if (target.xyz > 0)

{

            if (target.abc  ==  0 && puf..abc != 0)  //check 1

 

            {

                e.Description = "Invalid record";

            }

else if (target.abc == 78 && puf.abc == 78) //check 2

{

e.Description="Can't be the same";

}

return false;

}

return true;

 

    }

 

JonnyBee replied on Friday, January 13, 2012

Hi,

I may not fully understand your question but my suggestion would be to

A: Create 2 separate rules and add both with priority = 0 (default).

B: Concatenate the error mesages into one string and  then set e.Description.

A field may have more than one rule and my understanding from your description is that the conditions should be checked independent of each other - hens I would create and add 2 separate rules.

The rule engine will run all rules at Priority lower or equal  ValidationRules.ProcessThroughPriority (default = 0) unless a rule explicitly sets e.StopProcessing = true.

San replied on Friday, January 20, 2012

Thanks! that solves my problem.

Copyright (c) Marimer LLC