public ActionResult Edit(Guid id, string firstName, string lastName, string emailAddress, string phoneNumber, string organisationName, string loginId)
        {
            Employer         employer    = null;
            LoginCredentials credentials = null;

            try
            {
                employer = _employersQuery.GetEmployer(id);
                if (employer == null)
                {
                    return(NotFound("employer", "id", id));
                }

                credentials = _loginCredentialsQuery.GetCredentials(employer.Id);
                if (credentials == null)
                {
                    return(NotFound("employer", "id", id));
                }

                // Update the employer.

                employer.FirstName    = firstName;
                employer.LastName     = lastName;
                employer.EmailAddress = string.IsNullOrEmpty(emailAddress) ? null : new EmailAddress {
                    Address = emailAddress
                };
                employer.PhoneNumber = _phoneNumbersQuery.GetPhoneNumber(phoneNumber, ActivityContext.Location.Country);

                // Update the organisation but only for verified organisations.

                if (employer.Organisation.IsVerified && organisationName != employer.Organisation.FullName)
                {
                    employer.Organisation = _organisationsQuery.GetVerifiedOrganisation(organisationName);
                }

                _employerAccountsCommand.UpdateEmployer(employer);

                // Update the credentials.

                credentials.LoginId = loginId;
                _loginCredentialsCommand.UpdateCredentials(employer.Id, credentials, User.Id().Value);
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(new UserModel <IEmployer, EmployerLoginModel>
            {
                User = employer,
                UserLogin = new EmployerLoginModel {
                    LoginId = credentials == null ? null : credentials.LoginId
                },
            }));
        }
Esempio n. 2
0
        private void CreateEmployer(IOrganisation organisation, CreateEmployerModel model)
        {
            var employer = new Employer
            {
                Organisation = organisation,
                SubRole      = model.SubRole,
                EmailAddress = new EmailAddress {
                    Address = model.EmailAddress, IsVerified = true
                },
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                JobTitle    = model.JobTitle,
                PhoneNumber = _phoneNumbersQuery.GetPhoneNumber(model.PhoneNumber, ActivityContext.Location.Country),
            };

            if (model.IndustryId != null)
            {
                employer.Industries = new List <Industry> {
                    _industriesQuery.GetIndustry(model.IndustryId.Value)
                }
            }
            ;

            // Create the account, where the password must be changed at next login.

            var credentials = new LoginCredentials
            {
                LoginId            = model.LoginId,
                Password           = model.Password,
                PasswordHash       = LoginCredentials.HashToString(model.Password),
                MustChangePassword = true,
            };

            _employerAccountsCommand.CreateEmployer(employer, credentials);

            var members = _accountReportsQuery.GetUsers(UserType.Member, DateTime.Now);

            _emailsCommand.TrySend(new NewEmployerWelcomeEmail(employer, model.LoginId, model.Password, members));
        }
Esempio n. 3
0
        private Employer Join(HttpContextBase context, EmployerAccount account, Action <Employer> createEmployer)
        {
            account.Prepare();
            account.Validate();

            // Create the organisation.

            var organisation = CreateOrganisation(account);

            // Create the employer.

            var employer = new Employer
            {
                FirstName    = account.FirstName,
                LastName     = account.LastName,
                EmailAddress = new EmailAddress {
                    Address = account.EmailAddress, IsVerified = true
                },
                PhoneNumber  = _phoneNumbersQuery.GetPhoneNumber(account.PhoneNumber, ActivityContext.Current.Location.Country),
                Organisation = organisation,
                SubRole      = account.SubRole,
                Industries   = _industriesQuery.GetIndustries(account.IndustryIds),
            };

            createEmployer(employer);

            // Log the user in.

            _authenticationManager.LogIn(context, employer, AuthenticationStatus.Authenticated);

            // Initialise.

            _referralsManager.CreateReferral(context.Request, employer.Id);
            InitialiseEmployerProfile(employer.Id);
            return(employer);
        }
Esempio n. 4
0
        public ActionResult Settings(SettingsModel settings)
        {
            var employer = CurrentEmployer;

            settings.CanEditOrganisationName = !employer.Organisation.IsVerified;
            settings.Industries  = _industriesQuery.GetIndustries();
            settings.Allocations = GetAllocations(employer);
            var credentials = _loginCredentialsQuery.GetCredentials(employer.Id);

            settings.HasLoginCredentials = credentials != null;

            try
            {
                // Validate before changing.

                settings.Prepare();
                settings.Validate();

                // Update the credentials.

                UpdateCredentials(employer.Id, credentials, settings.LoginId, settings.Password, settings.ConfirmPassword, settings.UseLinkedInProfile);

                // Update.

                employer.FirstName   = settings.FirstName;
                employer.LastName    = settings.LastName;
                employer.PhoneNumber = _phoneNumbersQuery.GetPhoneNumber(settings.PhoneNumber, ActivityContext.Current.Location.Country);
                employer.Industries  = settings.IndustryIds == null
                    ? null
                    : (from i in settings.IndustryIds select _industriesQuery.GetIndustry(i)).ToList();
                employer.SubRole  = settings.Role;
                employer.JobTitle = settings.JobTitle;

                _employerAccountsCommand.UpdateEmployer(employer);

                // Update the organisation.

                if (settings.CanEditOrganisationName)
                {
                    UpdateOrganisation(employer, settings.OrganisationName);
                }

                // Suggested candidates.

                UpdateSuggestedCandidates(employer, settings.ShowSuggestedCandidates, settings.SendSuggestedCandidates, settings.ReceiveSuggestedCandidates);

                // Communications.

                UpdateCommunicationSettings(employer.Id, settings.EmailEmployerUpdate, settings.EmailCampaign);

                // Reset the display name cached in the authentication details, in case the user updated any details that affect it.

                _authenticationManager.UpdateUser(HttpContext, employer, false);

                return(RedirectToReturnUrlWithConfirmation("Your changes have been saved."));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(settings));
        }