Ejemplo n.º 1
0
        public ActionResult PersonalDetails(PersonalDetailsMemberModel memberModel, PersonalDetailsPasswordsModel passwordsModel)
        {
            var memberId = User.Id();

            try
            {
                // Make sure everything has been supplied appropriately.

                Validate(memberId, memberModel, passwordsModel);

                // Check whether the member is logged in.

                Member member = null;
                if (memberId != null)
                {
                    member = _membersQuery.GetMember(memberId.Value);
                }

                // If there is no member then try to join now.

                if (member == null)
                {
                    member = TryJoin(memberModel, passwordsModel, Pageflow.FriendInvitationId);
                }

                // Update the member.

                if (member != null)
                {
                    // Update the member.

                    UpdateMember(member, memberModel);
                    UpdateAffiliationItems(member.Id);

                    // Send out an activation email if needed.

                    if (!member.IsActivated)
                    {
                        _accountVerificationsCommand.SendActivation(member, member.GetPrimaryEmailAddress().Address);
                    }

                    // Member exists and has been updated so move on.

                    return(Next());
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new JoinErrorHandler());
            }

            return(View(GetPersonalDetailsModel(memberId, memberModel, passwordsModel)));
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        private PersonalDetailsModel GetPersonalDetailsModel(Guid?memberId, PersonalDetailsMemberModel member, PersonalDetailsPasswordsModel passwords)
        {
            var model = GetModel <PersonalDetailsModel>(memberId);

            model.Member    = member;
            model.Passwords = passwords;

            var communityId = ActivityContext.Community.Id;

            model.AffiliationItems = communityId != null && memberId != null
                ? _memberAffiliationsQuery.GetItems(memberId.Value, communityId.Value)
                : null;

            model.Reference = new PersonalDetailsReferenceModel
            {
                Countries      = _locationQuery.GetCountries(),
                DefaultCountry = ActivityContext.Location.Country,
                SalaryRates    = SalaryRates,
            };

            return(model);
        }