@@ -144,17 +144,27 @@ public class CourseDataService : ICourseDataService
144144 private const string DelegateCountQuery =
145145 @"(SELECT COUNT(pr.CandidateID)
146146 FROM dbo.Progress AS pr WITH (NOLOCK)
147- INNER JOIN dbo.Candidates AS can WITH (NOLOCK) ON can.CandidateID = pr.CandidateID
147+ INNER JOIN dbo.Candidates AS can WITH (NOLOCK) ON can.CandidateID = pr.CandidateID
148+ INNER JOIN dbo.DelegateAccounts AS da WITH (NOLOCK) ON da.ID = pr.CandidateID
149+ INNER JOIN dbo.Users AS u WITH (NOLOCK) ON u.ID = da.UserID
150+ LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND ucd.centreID = da.centreID
148151 WHERE pr.CustomisationID = cu.CustomisationID
149- AND can.CentreID = @centreId
150- AND RemovedDate IS NULL) AS DelegateCount" ;
152+ AND can.CentreID = @centreId
153+ AND RemovedDate IS NULL
154+ AND ((ucd.Email IS NOT NULL AND ucd.Email like '%_@_%.__%')
155+ OR u.PrimaryEmail like '%_@_%.__%')) AS DelegateCount" ;
151156
152157 private const string CompletedCountQuery =
153158 @"(SELECT COUNT(pr.CandidateID)
154159 FROM dbo.Progress AS pr WITH (NOLOCK)
155- INNER JOIN dbo.Candidates AS can WITH (NOLOCK) ON can.CandidateID = pr.CandidateID
160+ INNER JOIN dbo.Candidates AS can WITH (NOLOCK) ON can.CandidateID = pr.CandidateID
161+ INNER JOIN dbo.DelegateAccounts AS da WITH (NOLOCK) ON da.ID = pr.CandidateID
162+ INNER JOIN dbo.Users AS u WITH (NOLOCK) ON u.ID = da.UserID
163+ LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND ucd.centreID = da.centreID
156164 WHERE pr.CustomisationID = cu.CustomisationID AND pr.Completed IS NOT NULL
157- AND can.CentreID = @centreId) AS CompletedCount" ;
165+ AND can.CentreID = @centreId
166+ AND ((ucd.Email IS NOT NULL AND ucd.Email like '%_@_%.__%')
167+ OR u.PrimaryEmail like '%_@_%.__%')) AS CompletedCount" ;
158168
159169 private const string AllAttemptsQuery =
160170 @"(SELECT COUNT(aa.AssessAttemptID)
@@ -1621,7 +1631,9 @@ FROM DelegateAccounts AS da
16211631 INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = cu.ApplicationID
16221632 WHERE da.CentreID = @centreId
16231633 AND p.CustomisationID = @customisationId
1624- AND ap.DefaultContentTypeID <> 4" ,
1634+ AND ap.DefaultContentTypeID <> 4
1635+ AND ((ucd.Email IS NOT NULL AND ucd.Email like '%_@_%.__%')
1636+ OR u.PrimaryEmail like '%_@_%.__%')" ,
16251637 new { customisationId , centreId }
16261638 ) ;
16271639 }
0 commit comments