Ejemplo n.º 1
0
        public async Task <IActionResult> Employer(EmployerEditModel m, [FromQuery] bool wizard)
        {
            var response = await _orchestrator.PostEmployerEditModelAsync(m, User.ToVacancyUser());

            if (!response.Success)
            {
                response.AddErrorsToModelState(ModelState);
            }

            if (!ModelState.IsValid)
            {
                var vm = await _orchestrator.GetEmployerViewModelAsync(m);

                vm.PageInfo.SetWizard(wizard);
                return(View(vm));
            }

            if (response.Data.HasLegalEntityAgreement == false)
            {
                return(RedirectToRoute(RouteNames.LegalEntityAgreement_SoftStop_Get));
            }

            return(wizard
                ? RedirectToRoute(RouteNames.Training_Get)
                : RedirectToRoute(RouteNames.Vacancy_Preview_Get, null, Anchors.AboutEmployerSection));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(EmployerEditModel input)
        {
            var owner = await this.userManager.GetUserAsync(this.User);

            if (owner.CompanyId != input.CompanyId)
            {
                return(this.NotFound());
            }



            try
            {
                await this.employeesManagerService.UpdateAsync(input);
            }
            catch (Exception e)
            {
                this.ModelState.AddModelError(string.Empty, e.Message);
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            return(this.RedirectToAction("Details", new { employerId = input.Id }));
        }
Ejemplo n.º 3
0
        public async Task <int> UpdateAsync(EmployerEditModel input)
        {
            var employer = await this.employersRepository
                           .All()
                           .FirstOrDefaultAsync(x => x.Id == input.Id);

            if (this.employersRepository.All().Select(x => x.PhoneNumber).Contains(input.PhoneNumber) && input.PhoneNumber != employer.PhoneNumber)
            {
                throw new Exception($"PhoneNumber {input.PhoneNumber} is already in use from another employer in your company.");
            }

            switch (employer.HasAccount)
            {
            case true when this.validationsService.IsExistUserPhoneNumber(input.PhoneNumber) && input.PhoneNumber != employer.PhoneNumber:
                throw new Exception($"There is already account with {input.PhoneNumber}");

            case true when !this.validationsService.IsExistUserPhoneNumber(input.PhoneNumber) & input.PhoneNumber != employer.PhoneNumber:
                await this.usersService.ChangeUserPhoneNumber(input.PhoneNumber, employer.AccountId);

                break;
            }

            employer.PhoneNumber = input.PhoneNumber;

            if (this.employersRepository.All().Select(x => x.Email).Contains(input.Email) && input.Email != employer.Email)
            {
                throw new Exception($"Email {input.Email} is already in use from another employer in your company.");
            }

            switch (employer.HasAccount)
            {
            case true when this.validationsService.IsExistUserEmail(input.Email) && input.Email != employer.Email:
                throw new Exception($"There is already account with {input.Email}");

            case true when !this.validationsService.IsExistUserEmail(input.Email) && input.Email != employer.Email:
                await this.usersService.ChangeUserEmail(input.Email, employer.AccountId);

                break;
            }

            employer.Email = input.Email;

            employer.FirstName  = input.FirstName;
            employer.MiddleName = input.MiddleName;
            employer.LastName   = input.LastName;

            await this.addressService.UpdateAsync(employer.AddressId, input.AddressCountry, input.AddressCity, input.AddressStreet,
                                                  input.AddressZipCode);

            employer.JobTitleId = await this.jobTitlesService.CreateAsync(input.JobTitleName);

            this.employersRepository.Update(employer);

            return(await this.employersRepository.SaveChangesAsync());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Employer(EmployerEditModel m, [FromQuery] bool wizard)
        {
            var info = GetVacancyEmployerInfoCookie(m.VacancyId);

            if (info == null)
            {
                //something went wrong, the matching cookie was not found
                //Redirect the user with validation error to allow them to continue
                ModelState.AddModelError(nameof(EmployerEditModel.SelectedOrganisationId),
                                         ValidationMessages.EmployerSelectionValidationMessages.EmployerSelectionRequired);
            }

            if (!ModelState.IsValid)
            {
                var vm = await _orchestrator.GetEmployerViewModelAsync(m, m.SearchTerm, m.Page, info?.AccountLegalEntityPublicHashedId);

                SetVacancyEmployerInfoCookie(vm.VacancyEmployerInfoModel);
                vm.Pager.OtherRouteValues.Add(nameof(wizard), wizard.ToString());
                vm.PageInfo.SetWizard(wizard);
                return(View(vm));
            }

            if (info.AccountLegalEntityPublicHashedId != m.SelectedOrganisationId)
            {
                info.AccountLegalEntityPublicHashedId = m.SelectedOrganisationId;
                info.HasLegalEntityChanged            = true;
                info.EmployerIdentityOption           = null;
                info.NewTradingName  = null;
                info.AnonymousName   = null;
                info.AnonymousReason = null;
            }

            SetVacancyEmployerInfoCookie(info);
            await _orchestrator.SetAccountLegalEntityPublicId(m, info, User.ToVacancyUser());

            if (_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList))
            {
                return(wizard
                    ? RedirectToRoute(RouteNames.Training_Get, new { Wizard = wizard })
                    : RedirectToRoute(RouteNames.EmployerCheckYourAnswersGet));
            }

            return(RedirectToRoute(RouteNames.EmployerName_Get, new { Wizard = wizard }));
        }