public IActionResult LearnerInformation(LearnerInformationViewModel model) { var data = TempData.Peek <DelegateRegistrationByCentreData>() !; var centreId = data.Centre !.Value; centreCustomPromptHelper.ValidateCustomPrompts( centreId, model.Answer1, model.Answer2, model.Answer3, model.Answer4, model.Answer5, model.Answer6, ModelState ); if (!ModelState.IsValid) { PopulateLearnerInformationExtraFields(model, data); return(View(model)); } data.SetLearnerInformation(model); TempData.Set(data); return(RedirectToAction("WelcomeEmail")); }
public void ValidateCustomPrompts_adds_error_for_missing_mandatory_answer() { // Given var customPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, mandatory: true); var customPrompt2 = CustomPromptsTestHelper.GetDefaultCustomPrompt(2, mandatory: true); var centreCustomPrompts = CustomPromptsTestHelper.GetDefaultCentreCustomPrompts( new List <CustomPrompt> { customPrompt1, customPrompt2 }, 1 ); var modelState = new ModelStateDictionary(); A.CallTo(() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(1)) .Returns(centreCustomPrompts); // When centreCustomPromptHelper.ValidateCustomPrompts(1, null, Answer2, null, null, null, null, modelState); // Then modelState["Answer1"].Errors.Count.Should().Be(1); modelState["Answer2"].Should().BeNull(); }
public IActionResult Index(EditDelegateFormData formData, int delegateId) { var centreId = User.GetCentreId(); centreCustomPromptHelper.ValidateCustomPrompts(formData, centreId, ModelState); if (!userService.NewAliasIsValid(formData.AliasId, delegateId, centreId)) { ModelState.AddModelError( nameof(EditDelegateFormData.AliasId), "A user with this alias ID is already registered at this centre" ); } if (!ModelState.IsValid) { return(ReturnToEditDetailsViewWithErrors(formData, delegateId, centreId)); } if (!userService.NewEmailAddressIsValid(formData.Email !, null, delegateId, centreId)) { ModelState.AddModelError( nameof(EditDetailsFormData.Email), "A user with this email address is already registered at this centre" ); return(ReturnToEditDetailsViewWithErrors(formData, delegateId, centreId)); } var(accountDetailsData, centreAnswersData) = AccountDetailsDataHelper.MapToUpdateAccountData( formData, delegateId, User.GetCentreId() ); userService.UpdateUserAccountDetailsViaDelegateAccount(accountDetailsData, centreAnswersData); return(RedirectToAction("Index", "ViewDelegate", new { delegateId })); }