Skip to content

Commit 8b8b281

Browse files
committed
TD-4645-pattern for email validation updated in the sql queries
1 parent ab6433e commit 8b8b281

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

DigitalLearningSolutions.Data/DataServices/CourseDataService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND u
153153
WHERE pr.CustomisationID = cu.CustomisationID
154154
AND can.CentreID = @centreId
155155
AND RemovedDate IS NULL
156-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%') AS DelegateCount";
156+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%') AS DelegateCount";
157157

158158
private const string CompletedCountQuery =
159159
@"(SELECT COUNT(pr.CandidateID)
@@ -164,7 +164,7 @@ INNER JOIN dbo.Users AS u WITH (NOLOCK) ON u.ID = da.UserID
164164
LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND ucd.centreID = da.centreID
165165
WHERE pr.CustomisationID = cu.CustomisationID AND pr.Completed IS NOT NULL
166166
AND can.CentreID = @centreId
167-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%') AS CompletedCount";
167+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%') AS CompletedCount";
168168

169169
private const string AllAttemptsQuery =
170170
@"(SELECT COUNT(aa.AssessAttemptID)
@@ -1123,7 +1123,7 @@ AND ap.DefaultContentTypeID <> 4
11231123
AND ((@answer3 IS NULL) OR ((@answer3 = 'No option selected' OR @answer3 = 'FREETEXTBLANKVALUE') AND (pr.Answer3 IS NULL OR LTRIM(RTRIM(pr.Answer3)) = ''))
11241124
OR ((@answer3 = 'FREETEXTNOTBLANKVALUE' AND pr.Answer3 IS NOT NULL AND LTRIM(RTRIM(pr.Answer3)) != '') OR (pr.Answer3 IS NOT NULL AND pr.Answer3 = @answer3)))
11251125
1126-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%'";
1126+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%'";
11271127

11281128
string orderBy;
11291129
string sortOrder;
@@ -1631,7 +1631,7 @@ FROM DelegateAccounts AS da
16311631
WHERE da.CentreID = @centreId
16321632
AND p.CustomisationID = @customisationId
16331633
AND ap.DefaultContentTypeID <> 4
1634-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%'",
1634+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%'",
16351635
new { customisationId, centreId }
16361636
);
16371637
}
@@ -1677,7 +1677,7 @@ AND ap.DefaultContentTypeID <> 4
16771677
AND ((@answer3 IS NULL) OR ((@answer3 = 'No option selected' OR @answer3 = 'FREETEXTBLANKVALUE') AND (pr.Answer3 IS NULL OR LTRIM(RTRIM(pr.Answer3)) = ''))
16781678
OR ((@answer3 = 'FREETEXTNOTBLANKVALUE' AND pr.Answer3 IS NOT NULL AND LTRIM(RTRIM(pr.Answer3)) != '') OR (pr.Answer3 IS NOT NULL AND pr.Answer3 = @answer3)))
16791679
1680-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%'";
1680+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%'";
16811681

16821682

16831683
var mainSql = "SELECT COUNT(*) AS TotalRecords " + fromTableQuery;
@@ -1778,7 +1778,7 @@ AND ap.DefaultContentTypeID <> 4
17781778
AND ((@answer3 IS NULL) OR ((@answer3 = 'No option selected' OR @answer3 = 'FREETEXTBLANKVALUE') AND (pr.Answer3 IS NULL OR LTRIM(RTRIM(pr.Answer3)) = ''))
17791779
OR ((@answer3 = 'FREETEXTNOTBLANKVALUE' AND pr.Answer3 IS NOT NULL AND LTRIM(RTRIM(pr.Answer3)) != '') OR (pr.Answer3 IS NOT NULL AND pr.Answer3 = @answer3)))
17801780
1781-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%'";
1781+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%'";
17821782

17831783
string orderBy;
17841784
string sortOrder;
@@ -1963,7 +1963,7 @@ FROM dbo.CandidateAssessments AS can WITH (NOLOCK)
19631963
INNER JOIN Users AS u WITH (NOLOCK) ON u.ID = can.DelegateUserID
19641964
LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = u.ID AND ucd.centreID = can.CentreID
19651965
WHERE can.CentreID = @centreId AND can.SelfAssessmentID = csa.SelfAssessmentID
1966-
AND can.RemovedDate IS NULL AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%') AS DelegateCount,
1966+
AND can.RemovedDate IS NULL AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%') AS DelegateCount,
19671967
(Select COUNT(*) FROM
19681968
(SELECT can.ID FROM dbo.CandidateAssessments AS can WITH (NOLOCK)
19691969
LEFT JOIN dbo.CandidateAssessmentSupervisors AS cas ON can.ID = cas.CandidateAssessmentID
@@ -2017,7 +2017,7 @@ FROM Customisations
20172017
WHERE CustomisationID = @customisationID ",
20182018
new { customisationId }).FirstOrDefault();
20192019

2020-
2020+
20212021
}
20222022
}
20232023
}

DigitalLearningSolutions.Data/DataServices/GroupsDataService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ JOIN DelegateAccounts AS da WITH (NOLOCK) ON da.ID = gd.DelegateID
174174
JOIN Users AS u WITH (NOLOCK) ON u.ID = da.UserID
175175
LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = u.ID AND ucd.CentreID = da.CentreID
176176
WHERE gd.GroupID = g.GroupID
177-
AND (u.PrimaryEmail like '%_@_%.__%' OR ucd.Email is NOT NULL)
177+
AND (u.PrimaryEmail like '%_@_%' OR ucd.Email is NOT NULL)
178178
AND da.Approved = 1 AND da.Active = 1) AS DelegateCount,
179179
({CourseCountSql}) AS CoursesCount,
180180
g.CreatedByAdminUserID AS AddedByAdminId,
@@ -213,7 +213,7 @@ public IEnumerable<Group> GetGroupsForCentre(int centreId)
213213
new { centreId }
214214
);
215215
}
216-
public IEnumerable<Group> GetGroupsForRegistrationResponse(int centreId, string? answer1, string? answer2, string? answer3, string? jobGroup, string? answer4, string? answer5, string? answer6)
216+
public IEnumerable<Group> GetGroupsForRegistrationResponse(int centreId, string? answer1, string? answer2, string? answer3, string? jobGroup, string? answer4, string? answer5, string? answer6)
217217
{
218218
return connection.Query<Group>(
219219
@$"{groupsSql}
@@ -337,7 +337,7 @@ FROM GroupDelegates AS gd
337337
JOIN Users AS u ON u.ID = da.UserID
338338
LEFT JOIN UserCentreDetails AS ucd ON ucd.UserID = u.ID AND ucd.CentreID = da.CentreID
339339
WHERE gd.GroupID = @groupId
340-
AND (u.PrimaryEmail like '%_@_%.__%' OR ucd.Email is NOT NULL)
340+
AND (u.PrimaryEmail like '%_@_%' OR ucd.Email is NOT NULL)
341341
AND da.Approved = 1 AND da.Active = 1",
342342
new { groupId }
343343
);

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ LEFT JOIN dbo.CandidateAssessmentSupervisorVerifications AS casv WITH (NOLOCK) O
248248
AND ((@isDelegateActive IS NULL) OR (@isDelegateActive = 1 AND (da.Active = 1)) OR (@isDelegateActive = 0 AND (da.Active = 0)))
249249
AND ((@removed IS NULL) OR (@removed = 1 AND (ca.RemovedDate IS NOT NULL)) OR (@removed = 0 AND (ca.RemovedDate IS NULL)))
250250
AND ((@submitted IS NULL) OR (@submitted = 1 AND (ca.SubmittedDate IS NOT NULL)) OR (@submitted = 0 AND (ca.SubmittedDate IS NULL)))
251-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%' ";
251+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%' ";
252252

253253
var groupBy = $@" GROUP BY
254254
da.CandidateNumber,
@@ -383,7 +383,7 @@ LEFT JOIN dbo.CandidateAssessmentSupervisors AS cas WITH (NOLOCK) ON ca.ID = cas
383383
var whereQuery = $@" WHERE sa.ID = @selfAssessmentId
384384
AND da.CentreID = @centreID AND csa.CentreID = @centreID
385385
AND (ca.RemovedDate IS NULL)
386-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%' ";
386+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%' ";
387387

388388
var groupBy = $@" GROUP BY
389389
da.CandidateNumber,
@@ -473,7 +473,7 @@ LEFT OUTER JOIN AdminAccounts AS aaEnrolledBy WITH (NOLOCK) ON aaEnrolledBy.ID =
473473
AND ((@isDelegateActive IS NULL) OR (@isDelegateActive = 1 AND (da.Active = 1)) OR (@isDelegateActive = 0 AND (da.Active = 0)))
474474
AND ((@removed IS NULL) OR (@removed = 1 AND (ca.RemovedDate IS NOT NULL)) OR (@removed = 0 AND (ca.RemovedDate IS NULL)))
475475
AND ((@submitted IS NULL) OR (@submitted = 1 AND (ca.SubmittedDate IS NOT NULL)) OR (@submitted = 0 AND (ca.SubmittedDate IS NULL)))
476-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%' ";
476+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%' ";
477477

478478
var groupBy = $@" GROUP BY
479479
da.CandidateNumber,
@@ -577,7 +577,7 @@ LEFT OUTER JOIN AdminAccounts AS aaEnrolledBy WITH (NOLOCK) ON aaEnrolledBy.ID =
577577
AND ((@isDelegateActive IS NULL) OR (@isDelegateActive = 1 AND (da.Active = 1)) OR (@isDelegateActive = 0 AND (da.Active = 0)))
578578
AND ((@removed IS NULL) OR (@removed = 1 AND (ca.RemovedDate IS NOT NULL)) OR (@removed = 0 AND (ca.RemovedDate IS NULL)))
579579
AND ((@submitted IS NULL) OR (@submitted = 1 AND (ca.SubmittedDate IS NOT NULL)) OR (@submitted = 0 AND (ca.SubmittedDate IS NULL)))
580-
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%' ";
580+
AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%' ";
581581

582582
var groupBy = $@" GROUP BY
583583
da.CandidateNumber,

DigitalLearningSolutions.Data/DataServices/UserDataService/DelegateUserCardDataService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND u
187187
188188
AND Approved = 1
189189
190-
AND EmailAddress LIKE '%_@_%.__%'";
190+
AND EmailAddress LIKE '%_@_%'";
191191
public DelegateUserCard? GetDelegateUserCardById(int id)
192192
{
193193
var user = connection.Query<DelegateUserCard>(
@@ -224,15 +224,15 @@ public int GetCountDelegateUserCardsForExportByCentreId(String searchString, str
224224
{
225225
searchString = searchString.Trim();
226226
}
227-
227+
228228
if (groupId.HasValue)
229229
{
230230
var groupDelegatesForCentre = $@"SELECT DelegateID FROM GroupDelegates WHERE GroupID in (
231231
SELECT GroupID FROM Groups WHERE CentreID = @centreId AND RemovedDate IS NULL
232232
)";
233233
DelegatewhereConditon += "AND D.ID IN ( " + groupDelegatesForCentre + " AND GroupID = @groupId )";
234234
}
235-
235+
236236

237237
var delegateCountQuery = @$"SELECT COUNT(*) AS Matches FROM ( " + DelegateUserExportSelectQuery + " ) D " + DelegatewhereConditon;
238238

@@ -339,7 +339,7 @@ public List<DelegateUserCard> GetDelegateUserCardsForExportByCentreId(String sea
339339
)";
340340
if (groupId.HasValue)
341341
DelegatewhereConditon += "AND D.ID IN ( " + groupDelegatesForCentre + " AND GroupID = @groupId )";
342-
342+
343343

344344
string orderBy;
345345

@@ -424,7 +424,7 @@ public List<DelegateUserCard> GetDelegatesNotRegisteredForGroupByGroupId(int gro
424424
WHERE da.CentreId = @centreId
425425
AND da.Approved = 1
426426
AND da.Active = 1
427-
AND (u.PrimaryEmail like '%_@_%.__%' OR ucd.Email IS NOT NULL)
427+
AND (u.PrimaryEmail like '%_@_%' OR ucd.Email IS NOT NULL)
428428
AND NOT EXISTS (SELECT DelegateID FROM GroupDelegates WHERE DelegateID = da.ID
429429
AND GroupID = @groupId)",
430430
new

0 commit comments

Comments
 (0)