diff --git a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs index 0502613e04..2f388ba5cc 100644 --- a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs @@ -1007,6 +1007,8 @@ public void GetDelegatesOnCourseForExport_returns_expected_values() // Given var expectedFirstRecord = new CourseDelegateForExport { + CustomisationName = "Standard", + ApplicationName = "Entry Level - Win XP, Office 2003/07 OLD", IsDelegateActive = true, CandidateNumber = "PC97", CompleteBy = null, diff --git a/DigitalLearningSolutions.Data.Tests/Services/CourseDelegatesDownloadFileServiceTests.cs b/DigitalLearningSolutions.Data.Tests/Services/CourseDelegatesDownloadFileServiceTests.cs index 93061d725f..b811c32afe 100644 --- a/DigitalLearningSolutions.Data.Tests/Services/CourseDelegatesDownloadFileServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/Services/CourseDelegatesDownloadFileServiceTests.cs @@ -26,6 +26,8 @@ public class CourseDelegatesDownloadFileServiceTests { new CourseDelegateForExport { + ApplicationName = "Course One", + CustomisationName = "v1", CandidateNumber = "TM68", DelegateFirstName = "Philip", DelegateLastName = "Barber", @@ -54,6 +56,8 @@ public class CourseDelegatesDownloadFileServiceTests }, new CourseDelegateForExport { + ApplicationName = "Course One", + CustomisationName = "v1", CandidateNumber = "ES1", DelegateFirstName = "Jonathan", DelegateLastName = "Bennett", @@ -82,6 +86,8 @@ public class CourseDelegatesDownloadFileServiceTests }, new CourseDelegateForExport { + ApplicationName = "Course One", + CustomisationName = "v1", CandidateNumber = "NB8", DelegateFirstName = "Erik", DelegateLastName = "Griffin", @@ -108,6 +114,66 @@ public class CourseDelegatesDownloadFileServiceTests Duration = 1, DiagnosticScore = 0, }, + new CourseDelegateForExport + { + ApplicationName = "Course Two", + CustomisationName = "v1", + CandidateNumber = "TM68", + DelegateFirstName = "Philip", + DelegateLastName = "Barber", + DelegateEmail = "mtc@.o", + IsDelegateActive = true, + IsProgressLocked = false, + LastUpdated = new DateTime(2018, 03, 08), + Enrolled = new DateTime(2012, 05, 24), + CompleteBy = null, + RemovedDate = null, + Completed = null, + AllAttempts = 1, + AttemptsPassed = 0, + RegistrationAnswer1 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + RegistrationAnswer2 = "xxxxxxx", + RegistrationAnswer3 = null, + RegistrationAnswer4 = null, + RegistrationAnswer5 = null, + RegistrationAnswer6 = null, + Answer1 = null, + Answer2 = null, + Answer3 = null, + LoginCount = 2, + Duration = 0, + DiagnosticScore = 0, + }, + new CourseDelegateForExport + { + ApplicationName = "Course Two", + CustomisationName = "v1", + CandidateNumber = "ES1", + DelegateFirstName = "Jonathan", + DelegateLastName = "Bennett", + DelegateEmail = "slumrdaiehn.b@g", + IsDelegateActive = true, + IsProgressLocked = false, + LastUpdated = new DateTime(2018, 03, 08), + Enrolled = new DateTime(2010, 09, 22), + CompleteBy = null, + RemovedDate = null, + Completed = new DateTime(2018, 03, 08), + AllAttempts = 1, + AttemptsPassed = 1, + RegistrationAnswer1 = "Senior Implementation and Business Change Manager", + RegistrationAnswer2 = "test2", + RegistrationAnswer3 = null, + RegistrationAnswer4 = null, + RegistrationAnswer5 = null, + RegistrationAnswer6 = null, + Answer1 = null, + Answer2 = null, + Answer3 = null, + LoginCount = 2, + Duration = 0, + DiagnosticScore = 0, + }, }; private ICourseAdminFieldsService courseAdminFieldsService = null!; @@ -143,7 +209,7 @@ public void GetDelegateDownloadFileForCourse_returns_expected_excel_data() ); A.CallTo(() => courseDataService.GetDelegatesOnCourseForExport(customisationId, centreId)) - .Returns(courseDelegates); + .Returns(courseDelegates.Where(c => c.ApplicationName == "Course One")); var centreRegistrationPrompts = new List { @@ -193,17 +259,17 @@ public void GetCourseDelegateDownloadFile_returns_expected_excel_data() Courses = new[] { new CourseStatisticsWithAdminFieldResponseCounts - { ApplicationName = "Course One", CustomisationId = 1 }, + { ApplicationName = "Course One", CustomisationName = "v1", CustomisationId = 1 }, new CourseStatisticsWithAdminFieldResponseCounts - { ApplicationName = "Course Two", CustomisationId = 2 }, + { ApplicationName = "Course Two", CustomisationName = "v1", CustomisationId = 2 }, }, } ); A.CallTo(() => courseDataService.GetDelegatesOnCourseForExport(1, centreId)) - .Returns(courseDelegates); + .Returns(courseDelegates.Where(c => c.ApplicationName == "Course One")); A.CallTo(() => courseDataService.GetDelegatesOnCourseForExport(2, centreId)) - .Returns(courseDelegates.Where(c => c.CandidateNumber != "NB8")); + .Returns(courseDelegates.Where(c => c.ApplicationName == "Course Two")); var centreRegistrationPrompts = new List { diff --git a/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTest.xlsx b/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTest.xlsx index a2333d4b52..2654052d40 100644 Binary files a/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTest.xlsx and b/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTest.xlsx differ diff --git a/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTestBU.xlsx b/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTestBU.xlsx new file mode 100644 index 0000000000..8ab2dc3774 Binary files /dev/null and b/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportAllDataDownloadTestBU.xlsx differ diff --git a/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportCurrentDataDownloadTest.xlsx b/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportCurrentDataDownloadTest.xlsx index 6a38ff4980..2b65a06b07 100644 Binary files a/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportCurrentDataDownloadTest.xlsx and b/DigitalLearningSolutions.Data.Tests/TestData/CourseDelegateExportCurrentDataDownloadTest.xlsx differ diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index 5eafdf43db..48f2e90373 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -726,7 +726,7 @@ AND Progress.SubmittedTime > @threeMonthsAgo AND Applications.DefaultContentTypeID <> 4 GROUP BY Applications.ApplicationID", new - { brandId, threeMonthsAgo } + { brandId, threeMonthsAgo } ); return query.ToDictionary( entry => entry.ApplicationID, @@ -812,6 +812,8 @@ public IEnumerable GetDelegatesOnCourseForExport(int cu { return connection.Query( $@"SELECT + ap.ApplicationName, + cu.CustomisationName, ca.CandidateID AS DelegateId, ca.CandidateNumber, ca.FirstName AS DelegateFirstName, diff --git a/DigitalLearningSolutions.Data/Services/CourseDelegatesDownloadFileService.cs b/DigitalLearningSolutions.Data/Services/CourseDelegatesDownloadFileService.cs index 9c4bd1a8b6..31cd3e3aff 100644 --- a/DigitalLearningSolutions.Data/Services/CourseDelegatesDownloadFileService.cs +++ b/DigitalLearningSolutions.Data/Services/CourseDelegatesDownloadFileService.cs @@ -33,6 +33,7 @@ public byte[] GetCourseDelegateDownloadFile( public class CourseDelegatesDownloadFileService : ICourseDelegatesDownloadFileService { + private const string CourseName = "Course name"; private const string LastName = "Last name"; private const string FirstName = "First name"; private const string Email = "Email"; @@ -321,7 +322,7 @@ DataTable dataTable ) { dataTable.Columns.AddRange( - new[] { new DataColumn(LastName), new DataColumn(FirstName), new DataColumn(Email) } + new[] { new DataColumn(CourseName), new DataColumn(LastName), new DataColumn(FirstName), new DataColumn(Email) } ); foreach (var prompt in registrationRegistrationPrompts.CustomPrompts) @@ -397,6 +398,7 @@ private static void SetCommonRowValues( DataRow row ) { + row[CourseName] = courseDelegate.CourseName; row[LastName] = courseDelegate.DelegateLastName; row[FirstName] = courseDelegate.DelegateFirstName; row[Email] = courseDelegate.DelegateEmail; @@ -414,7 +416,6 @@ DataRow row courseDelegate.DelegateRegistrationPrompts[prompt.RegistrationField.Id - 1]; } } - row[DelegateId] = courseDelegate.CandidateNumber; row[Enrolled] = courseDelegate.Enrolled.Date; row[LastAccessed] = courseDelegate.LastUpdated.Date;