I have a little problem, here is my code:
public partial class Tourist
{
public Tourist()
{
Reserve = new HashSet<Reserve>();
}
public int touristID { get; set; }
[Required]
[StringLength(50)]
public string touristNAME { get; set; }
public DateTime touristBIRTHDAY { get; set; }
[Required]
[StringLength(50)]
public string touristEMAIL { get; set; }
public int touristPHONE { get; set; }
public virtual ICollection<Reserve> Reserve { get; set; }
}
}
How can I restrict touristBIRTHDAY to be +18 years old? I think that I have to use this function, but I don't know where to put it: Note: this function it's an example.
DateTime bday = DateTime.Parse(dob_main.Text);
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if(age < 18)
{
MessageBox.Show("Invalid Birth Day");
}
Thanks ;)
UPDATE: I follow the solution of Berkay Yaylaci, but I'm getting a NullReferenceException. It's seems that my value parameter is default, and then my method is not posting, why? What is the solution to that?