Skip to content

Commit 6202973

Browse files
TD-4238 Launching few courses from 'Current activities' or from 'Course set up' seeing back link as 'Completed activities'
1 parent 8c51508 commit 6202973

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
lines changed

DigitalLearningSolutions.Data/DataServices/CourseDataService.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int sup
125125
int selfAssessmentSupervisorRoleId, DateTime? completeByDate, int delegateUserId, int centreId, int? enrolledByAdminId);
126126

127127
bool IsCourseCompleted(int candidateId, int customisationId);
128-
128+
bool IsCourseCompleted(int candidateId, int customisationId, int progressID);
129129
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId);
130130

131131
public (IEnumerable<CourseStatistics>, int) GetCourseStatisticsAtCentre(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection, int centreId, int? categoryId, bool allCentreCourses, bool? hideInLearnerPortal,
@@ -137,7 +137,6 @@ int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int sup
137137
public IEnumerable<CourseStatistics> GetDelegateCourseStatisticsAtCentre(string searchString, int centreId, int? categoryId, bool allCentreCourses, bool? hideInLearnerPortal, string isActive, string categoryName, string courseTopic, string hasAdminFields);
138138

139139
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessmentStatisticsAtCentre(string searchString, int centreId, string categoryName, string isActive);
140-
bool IsCourseCurrent(int candidateId, int customisationId);
141140
}
142141

143142
public class CourseDataService : ICourseDataService
@@ -1820,27 +1819,26 @@ SELECT p.Completed
18201819
FROM Progress AS p INNER JOIN
18211820
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
18221821
Applications AS a ON cu.ApplicationID = a.ApplicationID
1823-
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId
1822+
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId
18241823
AND (NOT (p.Completed IS NULL)))
18251824
THEN CAST(1 AS BIT)
18261825
ELSE CAST(0 AS BIT) END",
18271826
new { candidateId, customisationId }
18281827
);
18291828
}
1830-
1831-
public bool IsCourseCurrent(int candidateId, int customisationId)
1829+
public bool IsCourseCompleted(int candidateId, int customisationId, int progressID)
18321830
{
18331831
return connection.ExecuteScalar<bool>(
18341832
@"SELECT CASE WHEN EXISTS (
18351833
SELECT p.Completed
18361834
FROM Progress AS p INNER JOIN
18371835
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
18381836
Applications AS a ON cu.ApplicationID = a.ApplicationID
1839-
WHERE (p.CandidateID = @candidateId) AND (p.CustomisationID = @customisationId)
1840-
AND ((p.Completed IS NULL)))
1837+
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId AND progressID =@progressID
1838+
AND (NOT (p.Completed IS NULL)))
18411839
THEN CAST(1 AS BIT)
18421840
ELSE CAST(0 AS BIT) END",
1843-
new { candidateId, customisationId }
1841+
new { candidateId, customisationId, progressID }
18441842
);
18451843
}
18461844

DigitalLearningSolutions.Web.Tests/Controllers/LearningMenu/IndexTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void Index_should_render_view()
2121
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(10);
2222

2323
// When
24-
var result = controller.Index(CustomisationId);
24+
var result = controller.Index(CustomisationId, progressID);
2525

2626
// Then
2727
var expectedModel = new InitialMenuViewModel(expectedCourseContent);
@@ -44,7 +44,7 @@ public void Index_should_redirect_to_section_page_if_one_section_in_course()
4444
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, customisationId, CentreId)).Returns(10);
4545

4646
// When
47-
var result = controller.Index(customisationId);
47+
var result = controller.Index(customisationId, progressID);
4848

4949
// Then
5050
result.Should()
@@ -74,7 +74,7 @@ public void Index_should_not_redirect_to_section_page_if_more_than_one_section_i
7474
A.CallTo(() => courseContentService.GetProgressId(CandidateId, customisationId)).Returns(10);
7575

7676
// When
77-
var result = controller.Index(customisationId);
77+
var result = controller.Index(customisationId, progressID);
7878

7979
// Then
8080
var expectedModel = new InitialMenuViewModel(expectedCourseContent);
@@ -91,7 +91,7 @@ public void Index_should_return_404_if_unknown_course()
9191
.Returns(3);
9292

9393
// When
94-
var result = controller.Index(CustomisationId);
94+
var result = controller.Index(CustomisationId, progressID);
9595

9696
// Then
9797
result.Should()
@@ -112,7 +112,7 @@ public void Index_should_return_404_if_unable_to_enrol()
112112
.Returns(null);
113113

114114
// When
115-
var result = controller.Index(CustomisationId);
115+
var result = controller.Index(CustomisationId, progressID);
116116

117117
// Then
118118
result.Should()
@@ -129,7 +129,7 @@ public void Index_always_calls_get_course_content()
129129
const int customisationId = 1;
130130

131131
// When
132-
controller.Index(1);
132+
controller.Index(1,2);
133133

134134
// Then
135135
A.CallTo(() => courseContentService.GetCourseContent(CandidateId, customisationId)).MustHaveHappened();
@@ -147,7 +147,7 @@ public void Index_valid_customisation_id_should_update_login_and_duration()
147147
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(progressId);
148148

149149
// When
150-
controller.Index(CustomisationId);
150+
controller.Index(CustomisationId, progressID);
151151

152152
// Then
153153
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(CandidateId, CustomisationId, A<ISession>._)).MustHaveHappened();
@@ -160,7 +160,7 @@ public void Index_invalid_customisation_id_should_not_insert_new_progress()
160160
A.CallTo(() => courseContentService.GetCourseContent(CandidateId, CustomisationId)).Returns(null);
161161

162162
// When
163-
controller.Index(CustomisationId);
163+
controller.Index(CustomisationId, progressID);
164164

165165
// Then
166166
A.CallTo(() => courseContentService.GetOrCreateProgressId(A<int>._, A<int>._, A<int>._)).MustNotHaveHappened();
@@ -173,7 +173,7 @@ public void Index_invalid_customisation_id_should_not_update_login_and_duration(
173173
A.CallTo(() => courseContentService.GetCourseContent(CandidateId, CustomisationId)).Returns(null);
174174

175175
// When
176-
controller.Index(CustomisationId);
176+
controller.Index(CustomisationId, progressID);
177177

178178
// Then
179179
A.CallTo(() => courseContentService.UpdateProgress(A<int>._)).MustNotHaveHappened();
@@ -186,7 +186,7 @@ public void Index_failing_to_insert_progress_should_not_update_progress()
186186
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(null);
187187

188188
// When
189-
controller.Index(CustomisationId);
189+
controller.Index(CustomisationId, progressID);
190190

191191
// Then
192192
A.CallTo(() => courseContentService.UpdateProgress(A<int>._)).MustNotHaveHappened();
@@ -203,7 +203,7 @@ public void Index_valid_customisationId_should_StartOrUpdate_course_sessions()
203203
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(1);
204204

205205
// When
206-
controller.Index(CustomisationId);
206+
controller.Index(CustomisationId, progressID);
207207

208208
// Then
209209
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(CandidateId, CustomisationId, httpContextSession)).MustHaveHappenedOnceExactly();
@@ -221,7 +221,7 @@ public void Index_invalid_customisationId_should_not_StartOrUpdate_course_sessio
221221
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(1);
222222

223223
// When
224-
controller.Index(CustomisationId);
224+
controller.Index(CustomisationId, progressID);
225225

226226
// Then
227227
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(A<int>._, A<int>._, A<ISession>._)).MustNotHaveHappened();
@@ -236,7 +236,7 @@ public void Index_unable_to_enrol_should_not_StartOrUpdate_course_sessions()
236236
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(null);
237237

238238
// When
239-
controller.Index(CustomisationId);
239+
controller.Index(CustomisationId, progressID);
240240

241241
// Then
242242
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(A<int>._, A<int>._, A<ISession>._)).MustNotHaveHappened();
@@ -298,7 +298,7 @@ public void Index_not_detects_id_manipulation_self_register_true()
298298
A.CallTo(() => courseService.GetSelfRegister(CustomisationId)).Returns(true);
299299

300300
// When
301-
var result = controller.Index(CustomisationId);
301+
var result = controller.Index(CustomisationId, progressID);
302302

303303
// Then
304304
result.Should()

DigitalLearningSolutions.Web.Tests/Controllers/LearningMenu/LearningMenuControllerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public partial class LearningMenuControllerTests
1717
private const int CandidateId = 11;
1818
private const int CentreId = 2;
1919
private const int CustomisationId = 12;
20+
const int progressID = 34;
2021
private const int SectionId = 199;
2122
private const int TutorialId = 842;
2223
private ISession httpContextSession = null!;

DigitalLearningSolutions.Web/Controllers/LearningMenuController/LearningMenuController.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ IClockUtility clockUtility
5858
}
5959

6060
[Route("/LearningMenu/{customisationId:int}")]
61-
public IActionResult Index(int customisationId)
61+
public IActionResult Index(int customisationId, int progressID)
6262
{
6363
var centreId = User.GetCentreIdKnownNotNull();
6464
var candidateId = User.GetCandidateIdKnownNotNull();
@@ -100,7 +100,7 @@ public IActionResult Index(int customisationId)
100100
courseContentService.UpdateProgress(progressId.Value);
101101
};
102102

103-
SetTempData(candidateId, customisationId);
103+
SetTempData(candidateId, customisationId, progressID);
104104

105105
var model = new InitialMenuViewModel(courseContent);
106106
return View(model);
@@ -599,11 +599,19 @@ private async Task IncreaseAuthenticatedUserExpiry()
599599

600600
private void SetTempData(int candidateId, int customisationId)
601601
{
602-
var isCurrent = courseService.IsCourseCurrent(candidateId, customisationId);
603-
if (isCurrent)
604-
TempData["LearningActivity"] = "Current";
602+
var isCompleted = courseService.IsCourseCompleted(candidateId, customisationId);
603+
if (isCompleted)
604+
TempData["LearningActivity"] = "Completed";
605605
else
606+
TempData["LearningActivity"] = "Current";
607+
}
608+
private void SetTempData(int candidateId, int customisationId,int progressID)
609+
{
610+
var isCompleted = courseService.IsCourseCompleted(candidateId, customisationId, progressID);
611+
if (isCompleted)
606612
TempData["LearningActivity"] = "Completed";
613+
else
614+
TempData["LearningActivity"] = "Current";
607615
}
608616

609617
private bool UniqueIdManipulationDetected(int candidateId, int customisationId)

DigitalLearningSolutions.Web/Services/CourseService.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ int diagCompletionThreshold
123123
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessments(string searchString, int centreId, string categoryName, string isActive);
124124
IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? centreId, int categoryId);
125125
bool IsCourseCompleted(int candidateId, int customisationId);
126+
bool IsCourseCompleted(int candidateId, int customisationId, int progressID);
126127
bool GetSelfRegister(int customisationId);
127128
IEnumerable<CurrentCourse> GetCurrentCourses(int candidateId);
128129
void SetCompleteByDate(int progressId, int candidateId, DateTime? completeByDate);
@@ -132,7 +133,6 @@ int diagCompletionThreshold
132133
void EnrolOnSelfAssessment(int selfAssessmentId, int delegateUserId, int centreId);
133134
int GetNumberOfActiveCoursesAtCentreFilteredByCategory(int centreId, int? categoryId);
134135
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId);
135-
bool IsCourseCurrent(int candidateId, int customisationId);
136136
}
137137

138138
public class CourseService : ICourseService
@@ -571,10 +571,14 @@ public IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? cen
571571
return courseDataService.GetAvailableCourses(delegateId, centreId, categoryId);
572572
}
573573

574-
public bool IsCourseCompleted(int candidateId, int customisationId)
574+
public bool IsCourseCompleted(int candidateId, int customisationId )
575575
{
576576
return courseDataService.IsCourseCompleted(candidateId, customisationId);
577577
}
578+
public bool IsCourseCompleted(int candidateId, int customisationId, int progressID)
579+
{
580+
return courseDataService.IsCourseCompleted(candidateId, customisationId, progressID);
581+
}
578582

579583
public bool GetSelfRegister(int customisationId)
580584
{
@@ -620,10 +624,5 @@ public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId)
620624
{
621625
return courseDataService.GetApplicationsAvailableToCentre(centreId);
622626
}
623-
624-
public bool IsCourseCurrent(int candidateId, int customisationId)
625-
{
626-
return courseDataService.IsCourseCurrent(candidateId,customisationId);
627-
}
628627
}
629628
}

DigitalLearningSolutions.Web/Views/LearningPortal/Completed/CompletedCourseCard/_CompletedCourseCard.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
asp-controller="LearningMenu"
3939
asp-action="Index"
4040
asp-route-customisationId="@Model.Id"
41+
asp-route-progressID="@Model.ProgressId"
4142
role="button">
4243
Launch course <span class="nhsuk-u-visually-hidden">@Model.Name</span>
4344
</a>

DigitalLearningSolutions.Web/Views/LearningPortal/Current/CurrentCourseCard/_CurrentCourseCard.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
asp-controller="LearningMenu"
4747
asp-action="Index"
4848
asp-route-customisationId="@Model.Id"
49+
asp-route-progressID="@Model.ProgressId"
4950
role="button">
5051
Launch course <span class="nhsuk-u-visually-hidden">@Model.Name</span>
5152
</a>

0 commit comments

Comments
 (0)