Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions DigitalLearningSolutions.Data/DataServices/CourseDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int sup
int selfAssessmentSupervisorRoleId, DateTime? completeByDate, int delegateUserId, int centreId, int? enrolledByAdminId);

bool IsCourseCompleted(int candidateId, int customisationId);

bool IsCourseCompleted(int candidateId, int customisationId, int progressID);
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId);

public (IEnumerable<CourseStatistics>, int) GetCourseStatisticsAtCentre(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection, int centreId, int? categoryId, bool allCentreCourses, bool? hideInLearnerPortal,
Expand Down Expand Up @@ -1819,13 +1819,28 @@ SELECT p.Completed
FROM Progress AS p INNER JOIN
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
Applications AS a ON cu.ApplicationID = a.ApplicationID
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId
AND (NOT (p.Completed IS NULL)))
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END",
new { candidateId, customisationId }
);
}
public bool IsCourseCompleted(int candidateId, int customisationId, int progressID)
{
return connection.ExecuteScalar<bool>(
@"SELECT CASE WHEN EXISTS (
SELECT p.Completed
FROM Progress AS p INNER JOIN
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
Applications AS a ON cu.ApplicationID = a.ApplicationID
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId AND progressID =@progressID
AND (NOT (p.Completed IS NULL)))
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END",
new { candidateId, customisationId, progressID }
);
}

public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Index_should_render_view()
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(10);

// When
var result = controller.Index(CustomisationId);
var result = controller.Index(CustomisationId, progressID);

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

// When
var result = controller.Index(customisationId);
var result = controller.Index(customisationId, progressID);

// Then
result.Should()
Expand Down Expand Up @@ -74,7 +74,7 @@ public void Index_should_not_redirect_to_section_page_if_more_than_one_section_i
A.CallTo(() => courseContentService.GetProgressId(CandidateId, customisationId)).Returns(10);

// When
var result = controller.Index(customisationId);
var result = controller.Index(customisationId, progressID);

// Then
var expectedModel = new InitialMenuViewModel(expectedCourseContent);
Expand All @@ -91,7 +91,7 @@ public void Index_should_return_404_if_unknown_course()
.Returns(3);

// When
var result = controller.Index(CustomisationId);
var result = controller.Index(CustomisationId, progressID);

// Then
result.Should()
Expand All @@ -112,7 +112,7 @@ public void Index_should_return_404_if_unable_to_enrol()
.Returns(null);

// When
var result = controller.Index(CustomisationId);
var result = controller.Index(CustomisationId, progressID);

// Then
result.Should()
Expand All @@ -129,7 +129,7 @@ public void Index_always_calls_get_course_content()
const int customisationId = 1;

// When
controller.Index(1);
controller.Index(1,2);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
controller.Index(CustomisationId);
controller.Index(CustomisationId, progressID);

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

// When
var result = controller.Index(CustomisationId);
var result = controller.Index(CustomisationId, progressID);

// Then
result.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class LearningMenuControllerTests
private const int CandidateId = 11;
private const int CentreId = 2;
private const int CustomisationId = 12;
const int progressID = 34;
private const int SectionId = 199;
private const int TutorialId = 842;
private ISession httpContextSession = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IClockUtility clockUtility
}

[Route("/LearningMenu/{customisationId:int}")]
public IActionResult Index(int customisationId)
public IActionResult Index(int customisationId, int progressID)
{
var centreId = User.GetCentreIdKnownNotNull();
var candidateId = User.GetCandidateIdKnownNotNull();
Expand Down Expand Up @@ -100,7 +100,7 @@ public IActionResult Index(int customisationId)
courseContentService.UpdateProgress(progressId.Value);
};

SetTempData(candidateId, customisationId);
SetTempData(candidateId, customisationId, progressID);

var model = new InitialMenuViewModel(courseContent);
return View(model);
Expand Down Expand Up @@ -605,6 +605,14 @@ private void SetTempData(int candidateId, int customisationId)
else
TempData["LearningActivity"] = "Current";
}
private void SetTempData(int candidateId, int customisationId,int progressID)
{
var isCompleted = courseService.IsCourseCompleted(candidateId, customisationId, progressID);
if (isCompleted)
TempData["LearningActivity"] = "Completed";
else
TempData["LearningActivity"] = "Current";
}

private bool UniqueIdManipulationDetected(int candidateId, int customisationId)
{
Expand Down
7 changes: 6 additions & 1 deletion DigitalLearningSolutions.Web/Services/CourseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ int diagCompletionThreshold
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessments(string searchString, int centreId, string categoryName, string isActive);
IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? centreId, int categoryId);
bool IsCourseCompleted(int candidateId, int customisationId);
bool IsCourseCompleted(int candidateId, int customisationId, int progressID);
bool GetSelfRegister(int customisationId);
IEnumerable<CurrentCourse> GetCurrentCourses(int candidateId);
void SetCompleteByDate(int progressId, int candidateId, DateTime? completeByDate);
Expand Down Expand Up @@ -570,10 +571,14 @@ public IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? cen
return courseDataService.GetAvailableCourses(delegateId, centreId, categoryId);
}

public bool IsCourseCompleted(int candidateId, int customisationId)
public bool IsCourseCompleted(int candidateId, int customisationId )
{
return courseDataService.IsCourseCompleted(candidateId, customisationId);
}
public bool IsCourseCompleted(int candidateId, int customisationId, int progressID)
{
return courseDataService.IsCourseCompleted(candidateId, customisationId, progressID);
}

public bool GetSelfRegister(int customisationId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
asp-controller="LearningMenu"
asp-action="Index"
asp-route-customisationId="@Model.Id"
asp-route-progressID="@Model.ProgressId"
role="button">
Launch course <span class="nhsuk-u-visually-hidden">@Model.Name</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
asp-controller="LearningMenu"
asp-action="Index"
asp-route-customisationId="@Model.Id"
asp-route-progressID="@Model.ProgressId"
role="button">
Launch course <span class="nhsuk-u-visually-hidden">@Model.Name</span>
</a>
Expand Down