Exemple #1
0
 public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (DateOfBirth < DateTime.Now.AddYears(-Constants.MaxAgeInsuree) || DateOfBirth > DateTime.Now)
     {
         yield return
             (new ValidationResult(
                  $"Invalid range for date of birth; must be between {0} and {Constants.MaxAgeInsuree} years.",
                  new[] { "DateOfBirth" }));
     }
     foreach (var validationResult in Addresses.Validate())
     {
         yield return(validationResult);
     }
     foreach (var validationResult in EmailAddresses.Validate())
     {
         yield return(validationResult);
     }
     foreach (var validationResult in PhoneNumbers.Validate())
     {
         yield return(validationResult);
     }
     foreach (var validationResult in Insurances.Validate())
     {
         yield return(validationResult);
     }
 }
Exemple #2
0
        /// <summary>
        /// Validates this object. It validates dependencies between properties and also calls Validate on child collections;
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns>A IEnumerable of ValidationResult. The IEnumerable is empty when the object is in a valid state.</returns>
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Type == PersonType.None)
            {
                yield return(new ValidationResult("Type can't be None.", new[] { "Type" }));
            }

            if (DateOfBirth < DateTime.Now.AddYears(Constants.MaxAgePerson * -1))
            {
                yield return(new ValidationResult("Invalid range for DateOfBirth; must be between today and 130 years ago.", new[] { "DateOfBirth" }));
            }
            if (DateOfBirth > DateTime.Now)
            {
                yield return(new ValidationResult("Invalid range for DateOfBirth; must be between today and 130 years ago.", new[] { "DateOfBirth" }));
            }

            foreach (var result in PhoneNumbers.Validate())
            {
                yield return(result);
            }

            foreach (var result in EmailAddresses.Validate())
            {
                yield return(result);
            }

            foreach (var result in HomeAddress.Validate())
            {
                yield return(result);
            }

            foreach (var result in WorkAddress.Validate())
            {
                yield return(result);
            }
        }