Example #1
0
        private void Validate(Guid?memberId, PersonalDetailsMemberModel memberModel, PersonalDetailsPasswordsModel passwordsModel)
        {
            memberModel.Prepare();

            // The passwords are only used if the user has not already joined.

            if (memberId == null)
            {
                passwordsModel.Prepare();
            }

            if (memberModel.Status == CandidateStatus.Unspecified)
            {
                memberModel.Status = null;
            }

            // Gather all errors.

            var errors = memberModel.GetValidationErrors().ToList();

            if (memberId == null)
            {
                if (!passwordsModel.AcceptTerms)
                {
                    errors = errors.Concat(new[] { new TermsValidationError("AcceptTerms") }).ToList();
                }
                errors = errors.Concat(passwordsModel.GetValidationErrors()).ToList();
            }

            // Validate the location separately.

            if (!string.IsNullOrEmpty(memberModel.Location))
            {
                var        location  = _locationQuery.ResolveLocation(_locationQuery.GetCountry(memberModel.CountryId), memberModel.Location);
                IValidator validator = new PostalSuburbValidator();
                if (!validator.IsValid(location))
                {
                    errors = errors.Concat(validator.GetValidationErrors("Location")).ToList();
                }
                else
                {
                    memberModel.Location = location.ToString();
                }
            }

            if (errors.Any())
            {
                throw new ValidationErrorsException(errors);
            }
        }
Example #2
0
        private void Validate(ContactDetailsMemberModel memberModel)
        {
            memberModel.Prepare();

            // Gather all errors.

            var errors = memberModel.GetValidationErrors().ToList();

            // Validate the location separately.

            if (!string.IsNullOrEmpty(memberModel.Location))
            {
                var country = memberModel.CountryId == null
                    ? ActivityContext.Location.Country
                    : _locationQuery.GetCountry(memberModel.CountryId.Value);
                var        location  = _locationQuery.ResolveLocation(country, memberModel.Location);
                IValidator validator = new PostalSuburbValidator();
                if (!validator.IsValid(location))
                {
                    errors = errors.Concat(validator.GetValidationErrors("Location")).ToList();
                }
                else
                {
                    memberModel.Location = location.ToString();
                }
            }

            // Gender and date of birth are required.

            if (memberModel.Gender == Gender.Unspecified)
            {
                errors.Add(new RequiredValidationError("Gender"));
            }
            if (memberModel.DateOfBirth == null)
            {
                errors.Add(new RequiredValidationError("DateOfBirth"));
            }

            if (errors.Any())
            {
                throw new ValidationErrorsException(errors);
            }
        }