Skip to content

Commit 790276d

Browse files
authored
Merge pull request #2749 from TechnologyEnhancedLearning/Develop/Fix/TD-4370-Accounts-appearing-DelegateActivities-export
TD-4370-Email format validation added in SQL query.
2 parents 0d9fc74 + 5663316 commit 790276d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

DigitalLearningSolutions.Data/DataServices/CourseDataService.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,25 @@ 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 COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%') AS DelegateCount";
151155

152156
private const string CompletedCountQuery =
153157
@"(SELECT COUNT(pr.CandidateID)
154158
FROM dbo.Progress AS pr WITH (NOLOCK)
155-
INNER JOIN dbo.Candidates AS can WITH (NOLOCK) ON can.CandidateID = pr.CandidateID
159+
INNER JOIN dbo.Candidates AS can WITH (NOLOCK) ON can.CandidateID = pr.CandidateID
160+
INNER JOIN dbo.DelegateAccounts AS da WITH (NOLOCK) ON da.ID = pr.CandidateID
161+
INNER JOIN dbo.Users AS u WITH (NOLOCK) ON u.ID = da.UserID
162+
LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND ucd.centreID = da.centreID
156163
WHERE pr.CustomisationID = cu.CustomisationID AND pr.Completed IS NOT NULL
157-
AND can.CentreID = @centreId) AS CompletedCount";
164+
AND can.CentreID = @centreId
165+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%') AS CompletedCount";
158166

159167
private const string AllAttemptsQuery =
160168
@"(SELECT COUNT(aa.AssessAttemptID)
@@ -1620,7 +1628,8 @@ FROM DelegateAccounts AS da
16201628
INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = cu.ApplicationID
16211629
WHERE da.CentreID = @centreId
16221630
AND p.CustomisationID = @customisationId
1623-
AND ap.DefaultContentTypeID <> 4",
1631+
AND ap.DefaultContentTypeID <> 4
1632+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%'",
16241633
new { customisationId, centreId }
16251634
);
16261635
}

0 commit comments

Comments
 (0)