jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

Combining AssertThat and RequiredIf #50

Closed ateetvora closed 9 years ago

ateetvora commented 9 years ago

Hi Jaroslaw,

I would like to know if it was possible to combine the two - "AssertThat" and "RequiredIf". This is the example of the business rule that I would like to code:

Model Class FirstName LastName EnrollmentDate

Validation - The EnrollmentDate should be greater than today's date if the FirstName = "John" and LastName = "Doe".

The first name and last name are not required fields.

jwaliszko commented 9 years ago

Hi, it is possible. You can combine multiple attributes if you wish. I don't know what have you tried, but the code is very simple and should look as follows:

public string FirstName { get; set; }
public string LastName { get; set; }

[RequiredIf("FirstName == 'John' && LastName == 'Doe'")]
[AssertThat("EnrollmentDate > Today()")]
public DateTime? EnrollmentDate { get; set; }