Skip to content

Commit ad6086f

Browse files
Merge branch 'master' of https://github.com/TechnologyEnhancedLearning/DLSV2 into Develop/Fixes/TD-1944_Fixed_showing_console_404_error_instead_of_410_error
2 parents 9355a0b + dc31214 commit ad6086f

File tree

20 files changed

+811
-175
lines changed

20 files changed

+811
-175
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FluentMigrator;
2+
3+
namespace DigitalLearningSolutions.Data.Migrations
4+
{
5+
[Migration(202308161530)]
6+
public class AlterGetCompletedCoursesForCandidateSP : Migration
7+
{
8+
public override void Up()
9+
{
10+
Execute.Sql(Properties.Resources.TD_1766_GetCompletedCoursesForCandidateTweak);
11+
}
12+
public override void Down()
13+
{
14+
Execute.Sql(Properties.Resources.TD_1766_GetCompletedCoursesForCandidateTweak_down);
15+
}
16+
}
17+
}

DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,10 @@
295295
<data name="TermsAndConditionsOldrecord" type="System.Resources.ResXFileRef, System.Windows.Forms">
296296
<value>..\Resources\TermsAndConditionsOldrecord.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
297297
</data>
298-
</root>
298+
<data name="TD_1766_GetCompletedCoursesForCandidateTweak_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
299+
<value>..\Scripts\TD-1766-GetCompletedCoursesForCandidateTweak_down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
300+
</data>
301+
<data name="TD_1766_GetCompletedCoursesForCandidateTweak" type="System.Resources.ResXFileRef, System.Windows.Forms">
302+
<value>..\Scripts\TD-1766-GetCompletedCoursesForCandidateTweak.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
303+
</data>
304+
</root>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/****** Object: StoredProcedure [dbo].[GetCompletedCoursesForCandidate] Script Date: 16/08/2023 12:17:34 ******/
2+
SET ANSI_NULLS ON
3+
GO
4+
5+
SET QUOTED_IDENTIFIER ON
6+
GO
7+
8+
-- =============================================
9+
-- Author: Kevin Whittaker
10+
-- Create date: 16/12/2016
11+
-- Description: Returns a list of completed courses for the candidate.
12+
-- 21/06/2021: Adds Applications.ArchivedDate field to output.
13+
-- =============================================
14+
ALTER PROCEDURE [dbo].[GetCompletedCoursesForCandidate]
15+
-- Add the parameters for the stored procedure here
16+
@CandidateID int
17+
AS
18+
BEGIN
19+
-- SET NOCOUNT ON added to prevent extra result sets from
20+
-- interfering with SELECT statements.
21+
SET NOCOUNT ON;
22+
23+
-- Insert statements for procedure here
24+
SELECT p.ProgressID, (CASE WHEN cu.CustomisationName <> '' THEN a.ApplicationName + ' - ' + cu.CustomisationName ELSE a.ApplicationName END) AS CourseName, p.CustomisationID, p.SubmittedTime AS LastAccessed, p.Completed,
25+
p.FirstSubmittedTime AS StartedDate, p.DiagnosticScore, p.PLLocked, cu.IsAssessed, dbo.CheckCustomisationSectionHasDiagnostic(p.CustomisationID, 0)
26+
AS HasDiagnostic, dbo.CheckCustomisationSectionHasLearning(p.CustomisationID, 0) AS HasLearning,
27+
COALESCE
28+
((SELECT COUNT(Passes) AS Passes
29+
FROM (SELECT COUNT(AssessAttemptID) AS Passes
30+
FROM AssessAttempts AS aa
31+
WHERE (CandidateID = p.CandidateID) AND (CustomisationID = p.CustomisationID) AND (Status = 1)
32+
GROUP BY SectionNumber) AS derivedtbl_2), 0) AS Passes,
33+
(SELECT COUNT(SectionID) AS Sections
34+
FROM Sections AS s
35+
WHERE (ApplicationID = cu.ApplicationID)) AS Sections, p.Evaluated, p.FollupUpEvaluated, a.ArchivedDate
36+
FROM Progress AS p INNER JOIN
37+
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
38+
Applications AS a ON cu.ApplicationID = a.ApplicationID
39+
WHERE (NOT (p.Completed IS NULL)) AND (p.CandidateID = @CandidateID)
40+
ORDER BY p.Completed DESC
41+
42+
END
43+
GO
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/****** Object: StoredProcedure [dbo].[GetCompletedCoursesForCandidate] Script Date: 16/08/2023 12:17:34 ******/
2+
SET ANSI_NULLS ON
3+
GO
4+
5+
SET QUOTED_IDENTIFIER ON
6+
GO
7+
8+
-- =============================================
9+
-- Author: Kevin Whittaker
10+
-- Create date: 16/12/2016
11+
-- Description: Returns a list of completed courses for the candidate.
12+
-- 21/06/2021: Adds Applications.ArchivedDate field to output.
13+
-- =============================================
14+
ALTER PROCEDURE [dbo].[GetCompletedCoursesForCandidate]
15+
-- Add the parameters for the stored procedure here
16+
@CandidateID int
17+
AS
18+
BEGIN
19+
-- SET NOCOUNT ON added to prevent extra result sets from
20+
-- interfering with SELECT statements.
21+
SET NOCOUNT ON;
22+
23+
-- Insert statements for procedure here
24+
SELECT p.ProgressID, a.ApplicationName + ' - ' + cu.CustomisationName AS CourseName, p.CustomisationID, p.SubmittedTime AS LastAccessed, p.Completed,
25+
p.FirstSubmittedTime AS StartedDate, p.DiagnosticScore, p.PLLocked, cu.IsAssessed, dbo.CheckCustomisationSectionHasDiagnostic(p.CustomisationID, 0)
26+
AS HasDiagnostic, dbo.CheckCustomisationSectionHasLearning(p.CustomisationID, 0) AS HasLearning,
27+
COALESCE
28+
((SELECT COUNT(Passes) AS Passes
29+
FROM (SELECT COUNT(AssessAttemptID) AS Passes
30+
FROM AssessAttempts AS aa
31+
WHERE (CandidateID = p.CandidateID) AND (CustomisationID = p.CustomisationID) AND (Status = 1)
32+
GROUP BY SectionNumber) AS derivedtbl_2), 0) AS Passes,
33+
(SELECT COUNT(SectionID) AS Sections
34+
FROM Sections AS s
35+
WHERE (ApplicationID = cu.ApplicationID)) AS Sections, p.Evaluated, p.FollupUpEvaluated, a.ArchivedDate
36+
FROM Progress AS p INNER JOIN
37+
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
38+
Applications AS a ON cu.ApplicationID = a.ApplicationID
39+
WHERE (NOT (p.Completed IS NULL)) AND (p.CandidateID = @CandidateID)
40+
ORDER BY p.Completed DESC
41+
42+
END
43+
GO

DigitalLearningSolutions.Data.Tests/DataServices/CentresDataServiceTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,49 @@ public void UpdateCentreManagerDetails_updates_centre()
184184
}
185185
}
186186

187+
[Test]
188+
public void AddCentre_inserts_new_centre()
189+
{
190+
using var transaction = new TransactionScope();
191+
try
192+
{
193+
// Given
194+
const string centreName = "TestCentre";
195+
const string contactFirstName = "TestFirstName";
196+
const string contactLastName = "TestLastName";
197+
const string contactEmail = "[email protected]";
198+
const string contactTelephone = "0123456789";
199+
const string registrationEmail = "[email protected]";
200+
201+
// When
202+
int insertedID = centresDataService.AddCentreForSuperAdmin(centreName, contactFirstName, contactLastName,
203+
contactEmail, contactTelephone, 1, 1, registrationEmail, "194.176.105", true,true);
204+
var insertedCentre = centresDataService.GetCentreDetailsById(insertedID)!;
205+
206+
// Then
207+
using (new AssertionScope())
208+
{
209+
insertedCentre.CentreName.Should().BeEquivalentTo(centreName);
210+
insertedCentre.ContactForename.Should().BeEquivalentTo(contactFirstName);
211+
insertedCentre.ContactSurname.Should().BeEquivalentTo(contactLastName);
212+
insertedCentre.ContactEmail.Should().BeEquivalentTo(contactEmail);
213+
insertedCentre.ContactTelephone.Should().BeEquivalentTo(contactTelephone);
214+
insertedCentre.CentreType.Should().BeEquivalentTo("NHS Organisation");
215+
insertedCentre.RegionName.Should().BeEquivalentTo("East Midlands");
216+
insertedCentre.RegistrationEmail.Should().BeEquivalentTo(registrationEmail);
217+
insertedCentre.ShowOnMap.Should().Be(true);
218+
insertedCentre.IpPrefix.Should().BeEquivalentTo("194.176.105");
219+
insertedCentre.CmsAdministratorSpots.Should().Be(5);
220+
insertedCentre.ContractType.Should().BeEquivalentTo("Basic");
221+
insertedCentre.TrainerSpots.Should().Be(0);
222+
}
223+
}
224+
finally
225+
{
226+
transaction.Dispose();
227+
}
228+
}
229+
187230
[Test]
188231
public void UpdateCentreWebsiteDetails_updates_centre()
189232
{

DigitalLearningSolutions.Data/DataServices/CentresDataService.cs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
namespace DigitalLearningSolutions.Data.DataServices
22
{
33
using Dapper;
4+
using DigitalLearningSolutions.Data.Extensions;
45
using DigitalLearningSolutions.Data.Models.Centres;
56
using DigitalLearningSolutions.Data.Models.DbModels;
67
using Microsoft.Extensions.Logging;
78
using System;
89
using System.Collections.Generic;
910
using System.Data;
11+
using System.Transactions;
1012

1113
public interface ICentresDataService
1214
{
@@ -63,6 +65,20 @@ void UpdateCentreDetails(
6365
byte[]? centreLogo
6466
);
6567

68+
public int AddCentreForSuperAdmin(
69+
string centreName,
70+
string? contactFirstName,
71+
string? contactLastName,
72+
string? contactEmail,
73+
string? contactPhone,
74+
int? centreTypeId,
75+
int? regionId,
76+
string? registrationEmail,
77+
string? ipPrefix,
78+
bool showOnMap,
79+
bool AddITSPcourses
80+
);
81+
6682
public void UpdateCentreDetailsForSuperAdmin(
6783
int centreId,
6884
string centreName,
@@ -223,7 +239,7 @@ FROM Centres AS c
223239
c.ServerSpaceBytes,
224240
c.CentreTypeID,
225241
ctp.CentreType,
226-
c.ShowOnMap
242+
c.pwEmail as RegistrationEmail
227243
FROM Centres AS c
228244
INNER JOIN Regions AS r ON r.RegionID = c.RegionID
229245
INNER JOIN ContractTypes AS ct ON ct.ContractTypeID = c.ContractTypeId
@@ -448,6 +464,84 @@ bool showOnMap
448464
);
449465
}
450466

467+
public int AddCentreForSuperAdmin(
468+
string centreName,
469+
string? contactFirstName,
470+
string? contactLastName,
471+
string? contactEmail,
472+
string? contactPhone,
473+
int? centreTypeId,
474+
int? regionId,
475+
string? registrationEmail,
476+
string? ipPrefix,
477+
bool showOnMap,
478+
bool AddITSPcourses
479+
)
480+
{
481+
int newCentreId;
482+
connection.EnsureOpen();
483+
using var transaction = connection.BeginTransaction();
484+
{
485+
newCentreId = connection.QuerySingle<int>(
486+
@"Insert INTO Centres
487+
(CentreName,
488+
ContactForename,
489+
ContactSurname,
490+
ContactEmail,
491+
ContactTelephone,
492+
CentreTypeID,
493+
RegionID,
494+
pwEmail,
495+
IPPrefix,
496+
ShowOnMap
497+
)
498+
OUTPUT Inserted.CentreID
499+
Values
500+
(
501+
@centreName,
502+
@contactFirstName,
503+
@contactLastName,
504+
@contactEmail,
505+
@contactPhone,
506+
@centreTypeId,
507+
@regionId,
508+
@registrationEmail,
509+
@ipPrefix,
510+
@showOnMap
511+
)",
512+
new
513+
{
514+
centreName,
515+
contactFirstName,
516+
contactLastName,
517+
contactEmail,
518+
contactPhone,
519+
centreTypeId,
520+
regionId,
521+
registrationEmail,
522+
ipPrefix,
523+
showOnMap
524+
},
525+
transaction
526+
);
527+
if (AddITSPcourses)
528+
{
529+
connection.Execute(
530+
@"INSERT INTO [CentreApplications] ([CentreID], [ApplicationID])
531+
SELECT @newCentreId, ApplicationID
532+
FROM Applications
533+
WHERE (Debug = 0) AND (ArchivedDate IS NULL) AND (ASPMenu = 1) AND (CoreContent = 1) AND (BrandID = 1) AND (LaunchedAssess = 1)",
534+
new { newCentreId },
535+
transaction
536+
);
537+
}
538+
539+
transaction.Commit();
540+
return newCentreId;
541+
}
542+
543+
}
544+
451545
public (string firstName, string lastName, string email) GetCentreManagerDetails(int centreId)
452546
{
453547
var info = connection.QueryFirstOrDefault<(string, string, string)>(

DigitalLearningSolutions.Data/DataServices/UserDataService/UserDataService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,24 @@ public void DeleteUserAndAccounts(int userId)
671671
BEGIN TRY
672672
BEGIN TRANSACTION
673673
674+
DELETE FROM aspProgress WHERE ProgressID IN (SELECT ProgressID FROM Progress WHERE CandidateID in (SELECT ID FROM DelegateAccounts where UserID = @userId))
675+
676+
DELETE FROM Progress WHERE CandidateID IN (SELECT ID FROM DelegateAccounts where UserID = @userId)
677+
678+
DELETE FROM ReportSelfAssessmentActivityLog where UserID = @userId
679+
680+
DELETE FROM SelfAssessmentResultSupervisorVerifications WHERE CandidateAssessmentSupervisorID IN ( SELECT ID
681+
FROM CandidateAssessmentSupervisors where CandidateAssessmentID IN (select ID from CandidateAssessments where DelegateUserID = @userId))
682+
683+
DELETE FROM CandidateAssessmentSupervisorVerifications WHERE CandidateAssessmentSupervisorID IN ( SELECT ID
684+
FROM CandidateAssessmentSupervisors where CandidateAssessmentID IN (select ID from CandidateAssessments where DelegateUserID = @userId))
685+
686+
DELETE FROM CandidateAssessmentSupervisors where CandidateAssessmentID IN (select ID from CandidateAssessments where DelegateUserID = @userId)
687+
688+
DELETE FROM CandidateAssessmentOptionalCompetencies WHERE CandidateAssessmentID IN (select ID from CandidateAssessments where DelegateUserID = @userId)
689+
690+
DELETE from CandidateAssessments where DelegateUserID = @userId
691+
674692
DELETE FROM SupervisorDelegates WHERE DelegateUserID = @userId
675693
676694
DELETE FROM UserCentreDetails WHERE UserID = @userId

DigitalLearningSolutions.Data/Models/Centres/Centre.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ public class Centre
4141
public string CentreType { get; set; }
4242
public long CandidateByteLimit { get; set; }
4343
public DateTime? ContractReviewDate { get; set; }
44+
public string? RegistrationEmail { get; set; }
45+
public bool AddITSPcourses { get; set; }
4446
}
4547
}

DigitalLearningSolutions.Data/Models/SectionContent/SectionContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public SectionContent(
6262
bool passwordSubmitted
6363
)
6464
{
65-
CourseTitle = $"{applicationName} - {customisationName}";
65+
CourseTitle = !String.IsNullOrEmpty(customisationName) ? $"{applicationName} - {customisationName}" : applicationName;
6666
CourseDescription = applicationInfo;
6767
SectionName = sectionName;
6868
HasLearning = hasLearning;

0 commit comments

Comments
 (0)