private IActionResult SaveSectionAndRedirect(SetSectionContentViewModel model) { var data = multiPageFormService.GetMultiPageFormData <AddNewCentreCourseTempData>( MultiPageFormDataFeature.AddNewCourse, TempData ); if (data !.SectionContentData == null) { data.SectionContentData = new List <SectionContentTempData>(); } data !.SectionContentData !.Add( new SectionContentTempData( model.Tutorials != null ? model.Tutorials.Select(GetCourseTutorialData) : new List <CourseTutorialTempData>() ) ); multiPageFormService.SetMultiPageFormData(data, MultiPageFormDataFeature.AddNewCourse, TempData); return(RedirectToNextSectionOrSummary( model.Index, new SetCourseContentViewModel(data.CourseContentData !) )); }
public IActionResult SetSectionContent(int sectionIndex) { var data = multiPageFormService.GetMultiPageFormData <AddNewCentreCourseTempData>( MultiPageFormDataFeature.AddNewCourse, TempData ); if (data.CourseContentData == null || data.Application == null) { throw new Exception( "Application amd CourseContentData should not be null at this point in the journey" ); } var section = data !.CourseContentData !.GetSelectedSections().ElementAt(sectionIndex); var tutorials = tutorialService.GetTutorialsForSection(section.SectionId).ToList(); if (!tutorials.Any()) { return(RedirectToNextSectionOrSummary( sectionIndex, new SetCourseContentViewModel(data.CourseContentData) )); } var showDiagnostic = data.Application !.DiagAssess; var model = new SetSectionContentViewModel(section, sectionIndex, showDiagnostic, tutorials); return(View("AddNewCentreCourse/SetSectionContent", model)); }
public IActionResult SetSectionContent( SetSectionContentViewModel model, string action ) { if (action == SaveAction) { return(SaveSectionAndRedirect(model)); } var bulkSelectResult = EditCourseSectionHelper.ProcessBulkSelect(model, action); return(bulkSelectResult ?? View("AddNewCentreCourse/SetSectionContent", model)); }
public void SetSectionContent_post_updates_temp_data_and_redirects_to_next_section_if_there_is_one() { // Given var section1 = new Section(1, "Test name 1"); var section2 = new Section(2, "Test name 2"); var model = new SetSectionContentViewModel(section1, 0, true); var courseContentTempData = new CourseContentTempData( new List <Section> { section1, section2 }, false, new List <int> { 1, 2 } ); SetAddNewCentreCourseTempData(application, courseContentTempData: courseContentTempData); A.CallTo( () => tutorialService.GetTutorialsForSection(A <int> ._) ).Returns(new List <Tutorial> { new Tutorial(1, "Test name", true, true) }); // When var result = controller.SetSectionContent(model, "save"); // Then using (new AssertionScope()) { A.CallTo( () => multiPageFormService.SetMultiPageFormData( A <AddNewCentreCourseTempData> .That.Matches(d => d.SectionContentData != null), MultiPageFormDataFeature.AddNewCourse, controller.TempData ) ).MustHaveHappenedOnceExactly(); result.Should().BeRedirectToActionResult().WithActionName("SetSectionContent"); } }