@@ -11,6 +11,7 @@ namespace DigitalLearningSolutions.Data.DataServices
1111 using System . Collections . Generic ;
1212 using System . Data ;
1313 using System . Linq ;
14+ using System . Threading . Tasks ;
1415
1516 public interface ICourseDataService
1617 {
@@ -96,7 +97,10 @@ int diagCompletionThreshold
9697
9798 IEnumerable < CourseDelegateForExport > GetDelegatesOnCourseForExport ( int customisationId , int centreId ) ;
9899
99- IEnumerable < CourseDelegateForExport > GetCourseDelegatesForExport ( string searchString , string sortBy , string sortDirection ,
100+ int GetCourseDelegatesCountForExport ( string searchString , string sortBy , string sortDirection ,
101+ int customisationId , int centreId , bool ? isDelegateActive , bool ? isProgressLocked , bool ? removed , bool ? hasCompleted , string ? answer1 , string ? answer2 , string ? answer3 ) ;
102+
103+ Task < IEnumerable < CourseDelegateForExport > > GetCourseDelegatesForExport ( string searchString , int offSet , int itemsPerPage , string sortBy , string sortDirection ,
100104 int customisationId , int centreId , bool ? isDelegateActive , bool ? isProgressLocked , bool ? removed , bool ? hasCompleted , string ? answer1 , string ? answer2 , string ? answer3 ) ;
101105
102106 int EnrolOnActivitySelfAssessment ( int selfAssessmentId , int candidateId , int supervisorId , string adminEmail ,
@@ -1348,7 +1352,75 @@ FROM DelegateAccounts AS da
13481352 ) ;
13491353 }
13501354
1351- public IEnumerable < CourseDelegateForExport > GetCourseDelegatesForExport ( string searchString , string sortBy , string sortDirection ,
1355+ public int GetCourseDelegatesCountForExport ( string searchString , string sortBy , string sortDirection ,
1356+ int customisationId , int centreId , bool ? isDelegateActive , bool ? isProgressLocked , bool ? removed , bool ? hasCompleted , string ? answer1 , string ? answer2 , string ? answer3 )
1357+ {
1358+
1359+ var fromTableQuery = $@ " FROM Customisations cu WITH (NOLOCK)
1360+ INNER JOIN Applications AS ap WITH (NOLOCK) ON ap.ApplicationID = cu.ApplicationID
1361+ INNER JOIN Progress AS pr WITH (NOLOCK) ON pr.CustomisationID = cu.CustomisationID
1362+ LEFT OUTER JOIN AdminAccounts AS aaSupervisor WITH (NOLOCK) ON aaSupervisor.ID = pr.SupervisorAdminId
1363+ LEFT OUTER JOIN Users AS uSupervisor WITH (NOLOCK) ON uSupervisor.ID = aaSupervisor.UserID
1364+ LEFT OUTER JOIN AdminAccounts AS aaEnrolledBy WITH (NOLOCK) ON aaEnrolledBy.ID = pr.EnrolledByAdminID
1365+ LEFT OUTER JOIN Users AS uEnrolledBy WITH (NOLOCK) ON uEnrolledBy.ID = aaEnrolledBy.UserID
1366+ INNER JOIN DelegateAccounts AS da WITH (NOLOCK) ON da.ID = pr.CandidateID
1367+ INNER JOIN Users AS u WITH (NOLOCK) ON u.ID = da.UserID
1368+ LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = da.UserID AND ucd.centreID = da.CentreID
1369+
1370+ WHERE (cu.CentreID = @centreId OR
1371+ (cu.AllCentres = 1 AND
1372+ EXISTS (SELECT CentreApplicationID
1373+ FROM CentreApplications cap
1374+ WHERE cap.ApplicationID = cu.ApplicationID AND
1375+ cap.CentreID = @centreID AND
1376+ cap.Active = 1)))
1377+ AND da.CentreID = @centreId
1378+ AND pr.CustomisationID = @customisationId
1379+ AND ap.DefaultContentTypeID <> 4
1380+
1381+ AND ( u.FirstName + ' ' + u.LastName + ' ' + COALESCE(ucd.Email, u.PrimaryEmail) + ' ' + COALESCE(CandidateNumber, '') LIKE N'%' + @searchString + N'%')
1382+ AND ((@isDelegateActive IS NULL) OR (@isDelegateActive = 1 AND (da.Active = 1)) OR (@isDelegateActive = 0 AND (da.Active = 0)))
1383+ AND ((@isProgressLocked IS NULL) OR (@isProgressLocked = 1 AND (pr.PLLocked = 1)) OR (@isProgressLocked = 0 AND (pr.PLLocked = 0)))
1384+ AND ((@removed IS NULL) OR (@removed = 1 AND (pr.RemovedDate IS NOT NULL)) OR (@removed = 0 AND (pr.RemovedDate IS NULL)))
1385+ AND ((@hasCompleted IS NULL) OR (@hasCompleted = 1 AND pr.Completed IS NOT NULL) OR (@hasCompleted = 0 AND pr.Completed IS NULL))
1386+
1387+ AND ((@answer1 IS NULL) OR ((@answer1 = 'No option selected' OR @answer1 = 'FREETEXTBLANKVALUE') AND (pr.Answer1 IS NULL OR TRIM(pr.Answer1) = ''))
1388+ OR (@answer1 = 'FREETEXTNOTBLANKVALUE' AND (pr.Answer1 IS NOT NULL OR pr.Answer1 = @answer1)))
1389+
1390+ AND ((@answer2 IS NULL) OR ((@answer2 = 'No option selected' OR @answer2 = 'FREETEXTBLANKVALUE') AND (pr.Answer2 IS NULL OR TRIM(pr.Answer2) = ''))
1391+ OR (@answer2 = 'FREETEXTNOTBLANKVALUE' AND (pr.Answer2 IS NOT NULL OR pr.Answer2 = @answer2)))
1392+
1393+ AND ((@answer3 IS NULL) OR ((@answer3 = 'No option selected' OR @answer3 = 'FREETEXTBLANKVALUE') AND (pr.Answer3 IS NULL OR TRIM(pr.Answer3) = ''))
1394+ OR (@answer3 = 'FREETEXTNOTBLANKVALUE' AND (pr.Answer3 IS NOT NULL OR pr.Answer3 = @answer3)))
1395+
1396+ AND COALESCE(ucd.Email, u.PrimaryEmail) LIKE '%_@_%.__%'" ;
1397+
1398+
1399+ var mainSql = "SELECT COUNT(*) AS TotalRecords " + fromTableQuery ;
1400+
1401+ return connection . ExecuteScalar < int > (
1402+ mainSql ,
1403+ new
1404+ {
1405+ searchString ,
1406+ sortBy ,
1407+ sortDirection ,
1408+ customisationId ,
1409+ centreId ,
1410+ isDelegateActive ,
1411+ isProgressLocked ,
1412+ removed ,
1413+ hasCompleted ,
1414+ answer1 ,
1415+ answer2 ,
1416+ answer3
1417+ } ,
1418+ commandTimeout : 3000
1419+ ) ;
1420+ }
1421+
1422+
1423+ public async Task < IEnumerable < CourseDelegateForExport > > GetCourseDelegatesForExport ( string searchString , int offSet , int itemsPerPage , string sortBy , string sortDirection ,
13521424 int customisationId , int centreId , bool ? isDelegateActive , bool ? isProgressLocked , bool ? removed , bool ? hasCompleted , string ? answer1 , string ? answer2 , string ? answer3 )
13531425 {
13541426
@@ -1437,6 +1509,8 @@ AND ap.DefaultContentTypeID <> 4
14371509 else
14381510 orderBy = " ORDER BY " + sortBy + sortOrder ;
14391511
1512+ orderBy += " OFFSET " + offSet + " ROWS FETCH NEXT " + itemsPerPage + " ROWS ONLY " ;
1513+
14401514
14411515 var mainSql = selectColumnQuery + fromTableQuery + orderBy ;
14421516
0 commit comments