Skip to content

Commit 203ed0e

Browse files
authored
Merge pull request #2954 from TechnologyEnhancedLearning/Develop/Fixes/TD-4340-Issuewiththe'Coursecontent'changelinkwhencreatingacoursefrom'Coursesetup'screen
TD-4340 Issue with the 'Course content' change link when creating a course from 'Course set up' screen
2 parents 52654f9 + 7a74b0a commit 203ed0e

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/CourseSetupController.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,10 @@ public IActionResult SetCourseContent(SetCourseContentViewModel model)
429429
}
430430
else
431431
{
432-
data!.SectionContentData = null;
432+
if (data!.SectionContentData == null)
433+
{
434+
data!.SectionContentData = null;
435+
}
433436
}
434437

435438
if (!ModelState.IsValid)
@@ -471,9 +474,18 @@ public IActionResult SetSectionContent(int sectionIndex)
471474
}
472475

473476
var showDiagnostic = data.Application!.DiagAssess;
474-
var model = new SetSectionContentViewModel(section, sectionIndex, showDiagnostic, tutorials);
477+
if (data.SectionContentData != null && data.SectionContentData.Count >=3 )
478+
{
479+
var tutorial = GetTutorialsFromSectionContentData(data.SectionContentData, tutorials);
480+
var model = new SetSectionContentViewModel(section, sectionIndex, showDiagnostic, tutorial);
481+
return View("AddNewCentreCourse/SetSectionContent", model);
482+
}
483+
else
484+
{
485+
var model = new SetSectionContentViewModel(section, sectionIndex, showDiagnostic, tutorials);
486+
return View("AddNewCentreCourse/SetSectionContent", model);
487+
}
475488

476-
return View("AddNewCentreCourse/SetSectionContent", model);
477489
}
478490

479491
[HttpPost("AddCourse/SetSectionContent")]
@@ -654,8 +666,14 @@ private IActionResult SaveSectionAndRedirect(SetSectionContentViewModel model)
654666
{
655667
data.SectionContentData = new List<SectionContentTempData>();
656668
}
657-
658-
data!.SectionContentData!.Add(
669+
if (data.SectionContentData != null && data.SectionContentData.Count >= 3)
670+
{
671+
return RedirectToNextSectionOrSummary(
672+
model.Index,
673+
new SetCourseContentViewModel(data.CourseContentData!)
674+
);
675+
}
676+
data!.SectionContentData!.Add(
659677
new SectionContentTempData(
660678
model.Tutorials != null
661679
? model.Tutorials.Select(GetCourseTutorialData)
@@ -727,6 +745,25 @@ private static IEnumerable<CourseStatisticsWithAdminFieldResponseCounts> UpdateC
727745

728746
return updatedCourses;
729747
}
748+
private IEnumerable<Tutorial> GetTutorialsFromSectionContentData(List<SectionContentTempData> sectionContentData, List<Tutorial> sectionTutorial)
749+
{
750+
if (sectionContentData == null || sectionTutorial == null) return new List<Tutorial>();
751+
var updatedRecords = sectionContentData
752+
.SelectMany(data => data.Tutorials)
753+
.Join(sectionTutorial,
754+
tempData => new { tempData.TutorialId, tempData.TutorialName }, // Match on both TutorialId and TutorialName
755+
index => new { index.TutorialId, index.TutorialName },
756+
(tempData, index) => new Tutorial
757+
{
758+
TutorialId = index.TutorialId,
759+
TutorialName = index.TutorialName,
760+
Status = tempData.LearningEnabled, // Updated from sectionContentData
761+
DiagStatus = tempData.DiagnosticEnabled // Updated from sectionContentData
762+
})
763+
.ToList();
764+
765+
return updatedRecords;
766+
}
730767

731768
}
732769
}

0 commit comments

Comments
 (0)