Пример #1
0
        public async Task <IActionResult> Summary(SummaryViewModel model)
        {
            var data = TempData.Peek <DelegateRegistrationData>() !;

            if (data.Centre == null || data.JobGroup == null)
            {
                return(RedirectToAction("Index"));
            }

            if (!ModelState.IsValid)
            {
                var viewModel = new SummaryViewModel(data);
                PopulateSummaryExtraFields(viewModel, data);
                viewModel.Terms = model.Terms;
                return(View(viewModel));
            }

            var centreId = (int)data.Centre;
            var refactoredTrackingSystemEnabled =
                await featureManager.IsEnabledAsync(FeatureFlags.RefactoredTrackingSystem);

            var userIp = Request.GetUserIpAddressFromRequest();

            try
            {
                var(candidateNumber, approved) =
                    registrationService.RegisterDelegate(
                        RegistrationMappingHelper.MapSelfRegistrationToDelegateRegistrationModel(data),
                        userIp,
                        refactoredTrackingSystemEnabled,
                        data.SupervisorDelegateId
                        );

                TempData.Clear();
                TempData.Add("candidateNumber", candidateNumber);
                TempData.Add("approved", approved);
                TempData.Add("centreId", centreId);
                return(RedirectToAction("Confirmation"));
            }
            catch (DelegateCreationFailedException e)
            {
                var error = e.Error;

                if (error.Equals(DelegateCreationError.UnexpectedError))
                {
                    return(new StatusCodeResult(500));
                }

                if (error.Equals(DelegateCreationError.EmailAlreadyInUse))
                {
                    return(RedirectToAction("Index"));
                }

                return(new StatusCodeResult(500));
            }
        }
        public void MapToDelegateRegistrationModel_returns_correct_DelegateRegistrationModel()
        {
            // Given
            var data = RegistrationDataHelper.SampleDelegateRegistrationData();

            // When
            var result = RegistrationMappingHelper.MapSelfRegistrationToDelegateRegistrationModel(data);

            // Then
            result.FirstName.Should().Be(data.FirstName);
            result.LastName.Should().Be(data.LastName);
            result.Email.Should().Be(data.Email);
            result.Centre.Should().Be(data.Centre);
            result.JobGroup.Should().Be(data.JobGroup);
            result.PasswordHash.Should().Be(data.PasswordHash);
            result.Answer1.Should().Be(data.Answer1);
            result.Answer2.Should().Be(data.Answer2);
            result.Answer3.Should().Be(data.Answer3);
        }