From 620f376137e9a81b93f56d9325a6bc1ad60e205c Mon Sep 17 00:00:00 2001 From: Daniel Bloxham Date: Tue, 13 Jul 2021 15:52:54 +0100 Subject: [PATCH] HEEDLS-470 - Corrected course statistics count from query --- .../DataServices/CourseDataService.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index 325c49b565..c7a48a6028 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -22,24 +22,32 @@ public interface ICourseDataService public class CourseDataService : ICourseDataService { private const string DelegateCountQuery = - @"(SELECT COUNT(CandidateID) + @"(SELECT COUNT(pr.CandidateID) FROM dbo.Progress AS pr - WHERE pr.CustomisationID = cu.CustomisationID) AS DelegateCount"; + INNER JOIN dbo.Candidates AS can ON can.CandidateID = pr.CandidateID + WHERE pr.CustomisationID = cu.CustomisationID + AND can.CentreID = @centreId) AS DelegateCount"; private const string CompletedCountQuery = - @"(SELECT COUNT(CandidateID) + @"(SELECT COUNT(pr.CandidateID) FROM dbo.Progress AS pr - WHERE pr.CustomisationID = cu.CustomisationID AND pr.Completed IS NOT NULL) AS CompletedCount"; + INNER JOIN dbo.Candidates AS can ON can.CandidateID = pr.CandidateID + WHERE pr.CustomisationID = cu.CustomisationID AND pr.Completed IS NOT NULL + AND can.CentreID = @centreId) AS CompletedCount"; private const string AllAttemptsQuery = - @"(SELECT COUNT(AssessAttemptID) + @"(SELECT COUNT(aa.AssessAttemptID) FROM dbo.AssessAttempts AS aa - WHERE aa.CustomisationID = cu.CustomisationID AND aa.[Status] IS NOT NULL) AS AllAttempts"; + INNER JOIN dbo.Candidates AS can ON can.CandidateID = aa.CandidateID + WHERE aa.CustomisationID = cu.CustomisationID AND aa.[Status] IS NOT NULL + AND can.CentreID = @centreId) AS AllAttempts"; private const string AttemptsPassedQuery = - @"(SELECT COUNT(AssessAttemptID) + @"(SELECT COUNT(aa.AssessAttemptID) FROM dbo.AssessAttempts AS aa - WHERE aa.CustomisationID = cu.CustomisationID AND aa.[Status] = 1) AS AttemptsPassed"; + INNER JOIN dbo.Candidates AS can ON can.CandidateID = aa.CandidateID + WHERE aa.CustomisationID = cu.CustomisationID AND aa.[Status] = 1 + AND can.CentreID = @centreId) AS AttemptsPassed"; private readonly IDbConnection connection; private readonly ILogger logger;