private Member TryJoin(PersonalDetailsMemberModel memberModel, IHavePasswords passwordsModel, Guid?friendInvitationId) { var account = new MemberAccount { FirstName = memberModel.FirstName, LastName = memberModel.LastName, EmailAddress = memberModel.EmailAddress }; var credentials = new AccountLoginCredentials { LoginId = memberModel.EmailAddress, Password = passwordsModel.Password, ConfirmPassword = passwordsModel.ConfirmPassword, }; // If the user is responding to an invitation then don't need to activate, unless they have changed their email. var friendInvitation = GetFriendInvitation(friendInvitationId); var acceptingFriendInvitation = friendInvitation != null && string.Equals(account.EmailAddress, friendInvitation.InviteeEmailAddress, StringComparison.OrdinalIgnoreCase); var requiresActivation = !acceptingFriendInvitation; // Join. var member = _accountsManager.Join(HttpContext, account, credentials, requiresActivation); // Deal with the invitations. if (acceptingFriendInvitation) { AcceptFriendInvitation(member.Id, friendInvitation); } return(member); }
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))); }
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); } }
private void UpdateMemberModel(PersonalDetailsMemberModel memberModel, Guid?parsedResumeId) { if (parsedResumeId == null) { return; } var parsedResume = _resumesQuery.GetParsedResume(parsedResumeId.Value); if (parsedResume == null) { return; } // Update those bits that are not already set. if (string.IsNullOrEmpty(memberModel.FirstName)) { memberModel.FirstName = parsedResume.FirstName; } if (string.IsNullOrEmpty(memberModel.LastName)) { memberModel.LastName = parsedResume.LastName; } var country = _locationQuery.GetCountry(memberModel.CountryId); if (string.IsNullOrEmpty(memberModel.Location)) { memberModel.Location = _locationQuery.ResolveLocation(country, parsedResume.Address == null ? null : parsedResume.Address.Location).ToString().NullIfEmpty(); } if (string.IsNullOrEmpty(memberModel.EmailAddress)) { if (parsedResume.EmailAddresses != null && parsedResume.EmailAddresses.Count != 0) { memberModel.EmailAddress = parsedResume.EmailAddresses[0].Address; } } if (string.IsNullOrEmpty(memberModel.PhoneNumber)) { var phoneNumber = GetPhoneNumber(parsedResume); if (phoneNumber != null) { memberModel.PhoneNumber = phoneNumber.Number; memberModel.PhoneNumberType = phoneNumber.Type; } } }
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); }
private void UpdateMember(Member member, PersonalDetailsMemberModel memberModel) { var candidate = _candidatesQuery.GetCandidate(member.Id); member.FirstName = memberModel.FirstName; member.LastName = memberModel.LastName; member.EmailAddresses = new List <EmailAddress> { new EmailAddress { Address = memberModel.EmailAddress } }; // Address. member.Address = new Address { Location = _locationQuery.ResolveLocation(_locationQuery.GetCountry(memberModel.CountryId), memberModel.Location) }; // Phone number. if (member.PhoneNumbers == null || member.PhoneNumbers.Count == 0) { member.PhoneNumbers = new List <PhoneNumber> { new PhoneNumber { Number = memberModel.PhoneNumber, Type = memberModel.PhoneNumberType } }; } else { member.PhoneNumbers[0].Number = memberModel.PhoneNumber; member.PhoneNumbers[0].Type = memberModel.PhoneNumberType; } // Visibility. Start with the current and then ensure each is set as appropriate. var visibility = member.VisibilitySettings.Professional.EmploymentVisibility; visibility = visibility.SetFlag(ProfessionalVisibility.Resume, memberModel.Visibility.IsFlagSet(ProfessionalVisibility.Resume)); if (visibility.IsFlagSet(ProfessionalVisibility.Resume)) { visibility = visibility.SetFlag(ProfessionalVisibility.Name, memberModel.Visibility.IsFlagSet(ProfessionalVisibility.Name)); visibility = visibility.SetFlag(ProfessionalVisibility.PhoneNumbers, memberModel.Visibility.IsFlagSet(ProfessionalVisibility.PhoneNumbers)); visibility = visibility.SetFlag(ProfessionalVisibility.RecentEmployers, memberModel.Visibility.IsFlagSet(ProfessionalVisibility.RecentEmployers)); } else { visibility = visibility.ResetFlag(ProfessionalVisibility.Name); visibility = visibility.ResetFlag(ProfessionalVisibility.PhoneNumbers); visibility = visibility.ResetFlag(ProfessionalVisibility.RecentEmployers); } visibility = visibility.SetFlag(ProfessionalVisibility.Salary, memberModel.Visibility.IsFlagSet(ProfessionalVisibility.Salary)); member.VisibilitySettings.Professional.EmploymentVisibility = visibility; // Update the member. _memberAccountsCommand.UpdateMember(member); // Status. candidate.Status = memberModel.Status ?? Defaults.CandidateStatus; candidate.DesiredSalary = memberModel.SalaryLowerBound == null ? null : new Salary { LowerBound = memberModel.SalaryLowerBound, Currency = Currency.AUD, Rate = memberModel.SalaryRate }; // Update the candidate. _candidatesCommand.UpdateCandidate(candidate); // Save the uploaded resume for the member. if (Pageflow.FileReferenceId != null) { var fileReference = _filesQuery.GetFileReference(Pageflow.FileReferenceId.Value); if (fileReference != null) { if (Pageflow.ParsedResumeId != null && Pageflow.IsResumeValid) { var parsedResume = _resumesQuery.GetParsedResume(Pageflow.ParsedResumeId.Value); _candidateResumesCommand.CreateResume(candidate, parsedResume.Resume.Clone(), fileReference); } else { _candidateResumesCommand.CreateResumeFile(candidate, fileReference); } } } }