Esempio n. 1
0
        /// <summary>
        ///     Validates the specified validation context.
        /// </summary>
        /// <param name="validationContext">The validation context.</param>
        /// <returns></returns>
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            //Last Name
            if (string.IsNullOrWhiteSpace(LastName))
            {
                yield return(new ValidationResult(
                                 string.Format(AppConstants.ErrorMessages.ShouldNotBeEmpty, Property(r => r.LastName)),
                                 new[] { Property(r => r.LastName).ToString(), "IsNullOrWhiteSpace" }));
            }

            //Email
            if (!Email.IsValidEmailAddress())
            {
                yield return(new ValidationResult(
                                 string.Format(AppConstants.ErrorMessages.MustBeValidEmail, Property(r => r.Email)),
                                 new[] { Property(r => r.Email).ToString(), "IsValidEmailAddress" }));
            }

            //Phone Number
            if (!HomePhone.IsValidPhoneNumber())
            {
                yield return(new ValidationResult(
                                 string.Format(AppConstants.ErrorMessages.MustBeValidPhoneNumber, Property(r => r.HomePhone)),
                                 new[] { Property(r => r.HomePhone).ToString(), "IsValidPhoneNumber" }));
            }

            //Phone Number
            if (!MobilePhone.IsValidPhoneNumber())
            {
                yield return(new ValidationResult(
                                 string.Format(AppConstants.ErrorMessages.MustBeValidPhoneNumber, Property(r => r.MobilePhone)),
                                 new[] { Property(r => r.MobilePhone).ToString(), "IsValidPhoneNumber" }));
            }

            //Phone Number
            if (!WorkPhone.IsValidPhoneNumber())
            {
                yield return(new ValidationResult(
                                 string.Format(AppConstants.ErrorMessages.MustBeValidPhoneNumber, Property(r => r.WorkPhone)),
                                 new[] { Property(r => r.WorkPhone).ToString(), "IsValidPhoneNumber" }));
            }
        }