Ejemplo n.º 1
0
        public ActionResult NewEmployer(Guid id, [Bind(Include = "LoginId,Password,EmailAddress,FirstName,LastName,PhoneNumber,JobTitle,SubRole,IndustryId")] CreateEmployerModel login)
        {
            var organisation = _organisationsQuery.GetOrganisation(id);

            if (organisation == null)
            {
                return(NotFound("organisation", "id", id));
            }

            // Can only create logins for verified organisations.

            if (!organisation.IsVerified)
            {
                ModelState.AddModelError(string.Empty, "Cannot create logins for unverified organisations.");
                return(View(new NewEmployerModel {
                    Organisation = organisation
                }));
            }

            if (login == null)
            {
                login = new CreateEmployerModel();
            }

            try
            {
                // Look for errors.

                login.Validate();

                // Create the login.

                CreateEmployer(organisation, login);

                // Get ready to create another.

                return(RedirectToRouteWithConfirmation(OrganisationsRoutes.NewEmployer, new { id }, HttpUtility.HtmlEncode("The account for " + login.FirstName + " " + login.LastName + " has been created.")));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            login.Industries = _industriesQuery.GetIndustries();

            return(View(new NewEmployerModel
            {
                Organisation = organisation,
                Employers = _employersQuery.GetOrganisationEmployers(organisation.Id),
                Employer = login
            }));
        }
Ejemplo 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));
        }