Skip to content

Commit bec7e65

Browse files
committed
Merge branch 'DLS-Release-v1.2.0' into UAT
2 parents dc61377 + 513009c commit bec7e65

File tree

17 files changed

+138
-74
lines changed

17 files changed

+138
-74
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public interface IFrameworkDataService
6262
int GetMaxFrameworkCompetencyID();
6363

6464
int GetMaxFrameworkCompetencyGroupID();
65+
int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId);
6566

6667
// Assessment questions:
6768
IEnumerable<AssessmentQuestion> GetAllCompetencyQuestions(int adminId);
@@ -198,7 +199,7 @@ int adminId
198199

199200
void UpdateFrameworkConfig(int frameworkId, int adminId, string? frameworkConfig);
200201

201-
void UpdateFrameworkCompetencyGroup(
202+
bool UpdateFrameworkCompetencyGroup(
202203
int frameworkCompetencyGroupId,
203204
int competencyGroupId,
204205
string name,
@@ -581,7 +582,7 @@ OUTPUT INSERTED.Id
581582
VALUES (@groupName, @groupDescription, @adminId)",
582583
new { groupName, groupDescription, adminId }
583584
);
584-
585+
585586
return existingId;
586587
}
587588

@@ -613,7 +614,7 @@ FROM [FrameworkCompetencyGroups]
613614
WHERE ([FrameworkID] = @frameworkId)), 0)+1, @frameworkId)",
614615
new { groupId, adminId, frameworkId }
615616
);
616-
617+
617618
return existingId;
618619
}
619620

@@ -973,7 +974,7 @@ FROM FrameworkCompetencies AS fc
973974
);
974975
}
975976

976-
public void UpdateFrameworkCompetencyGroup(
977+
public bool UpdateFrameworkCompetencyGroup(
977978
int frameworkCompetencyGroupId,
978979
int competencyGroupId,
979980
string name,
@@ -986,7 +987,7 @@ int adminId
986987
logger.LogWarning(
987988
$"Not updating framework competency group as it failed server side validation. AdminId: {adminId}, frameworkCompetencyGroupId: {frameworkCompetencyGroupId}, competencyGroupId: {competencyGroupId}, name: {name}"
988989
);
989-
return;
990+
return false;
990991
}
991992

992993
var usedElsewhere = connection.QuerySingle<int>(
@@ -1005,29 +1006,40 @@ int adminId
10051006
SET CompetencyGroupID = @newCompetencyGroupId, UpdatedByAdminID = @adminId
10061007
WHERE ID = @frameworkCompetencyGroupId",
10071008
new { newCompetencyGroupId, adminId, frameworkCompetencyGroupId }
1009+
10081010
);
10091011
if (numberOfAffectedRows < 1)
10101012
{
10111013
logger.LogWarning(
10121014
"Not updating competency group id as db update failed. " +
10131015
$"newCompetencyGroupId: {newCompetencyGroupId}, admin id: {adminId}, frameworkCompetencyGroupId: {frameworkCompetencyGroupId}"
10141016
);
1017+
return false;
1018+
}
1019+
else
1020+
{
1021+
return true;
10151022
}
10161023
}
1024+
else
1025+
{
1026+
return false;
1027+
}
10171028
}
10181029
else
10191030
{
10201031
var numberOfAffectedRows = connection.Execute(
10211032
@"UPDATE CompetencyGroups SET Name = @name, UpdatedByAdminID = @adminId, Description = @description
1022-
WHERE ID = @competencyGroupId",
1033+
WHERE ID = @competencyGroupId AND (Name <> @name OR Description <> @description)",
10231034
new { name, adminId, competencyGroupId, description }
10241035
);
10251036
if (numberOfAffectedRows < 1)
10261037
{
1027-
logger.LogWarning(
1028-
"Not updating competency group name as db update failed. " +
1029-
$"Name: {name}, admin id: {adminId}, competencyGroupId: {competencyGroupId}"
1030-
);
1038+
return false;
1039+
}
1040+
else
1041+
{
1042+
return true;
10311043
}
10321044
}
10331045
}
@@ -1047,7 +1059,7 @@ public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, st
10471059
@"UPDATE Competencies SET Name = @name, Description = @description, UpdatedByAdminID = @adminId, AlwaysShowDescription = CASE WHEN @alwaysShowDescription IS NULL THEN AlwaysShowDescription ELSE @alwaysShowDescription END
10481060
FROM Competencies INNER JOIN FrameworkCompetencies AS fc ON Competencies.ID = fc.CompetencyID
10491061
WHERE (fc.Id = @frameworkCompetencyId)",
1050-
new { name, description, adminId, frameworkCompetencyId, alwaysShowDescription}
1062+
new { name, description, adminId, frameworkCompetencyId, alwaysShowDescription }
10511063
);
10521064
if (numberOfAffectedRows < 1)
10531065
{
@@ -2407,20 +2419,20 @@ public IEnumerable<BulkCompetency> GetBulkCompetenciesForFramework(int framework
24072419
else
24082420
{
24092421
return connection.Query<BulkCompetency>(
2410-
@"SELECT fc.ID, cg.Name AS CompetencyGroup, cg.Description AS GroupDescription, c.Name AS Competency, c.Description AS CompetencyDescription, c.AlwaysShowDescription, STUFF((
2422+
@"SELECT fc.ID, ISNULL(cg.Name, '') AS CompetencyGroup, cg.Description AS GroupDescription, c.Name AS Competency, c.Description AS CompetencyDescription, c.AlwaysShowDescription, STUFF((
24112423
SELECT ', ' + f.FlagName
24122424
FROM Flags AS f
24132425
INNER JOIN CompetencyFlags AS cf ON f.ID = cf.FlagID
24142426
WHERE cf.CompetencyID = c.ID
24152427
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '') AS FlagsCsv
24162428
FROM
24172429
Competencies AS c INNER JOIN
2418-
FrameworkCompetencies AS fc ON c.ID = fc.CompetencyID INNER JOIN
2419-
FrameworkCompetencyGroups AS fcg ON fc.FrameworkCompetencyGroupID = fcg.ID INNER JOIN
2430+
FrameworkCompetencies AS fc ON c.ID = fc.CompetencyID LEFT JOIN
2431+
FrameworkCompetencyGroups AS fcg ON fc.FrameworkCompetencyGroupID = fcg.ID LEFT JOIN
24202432
CompetencyGroups AS cg ON fcg.CompetencyGroupID = cg.ID
24212433
WHERE (fc.FrameworkID = @frameworkId)
24222434
GROUP BY fc.ID, c.ID, cg.Name, cg.Description, c.Name, c.Description, c.AlwaysShowDescription, fcg.Ordering, fc.Ordering
2423-
ORDER BY fcg.Ordering, fc.Ordering",
2435+
ORDER BY COALESCE(fcg.Ordering,99999), fc.Ordering",
24242436
new { frameworkId }
24252437
);
24262438
}
@@ -2430,12 +2442,21 @@ public List<int> GetFrameworkCompetencyOrder(int frameworkId, List<int> framewor
24302442
{
24312443
return connection.Query<int>(
24322444
@"SELECT fc.ID
2433-
FROM FrameworkCompetencies AS fc INNER JOIN
2445+
FROM FrameworkCompetencies AS fc LEFT JOIN
24342446
FrameworkCompetencyGroups AS fcg ON fc.FrameworkCompetencyGroupID = fcg.ID
24352447
WHERE (fc.FrameworkID = @frameworkId) AND (fc.ID IN @frameworkCompetencyIds)
2436-
ORDER BY fcg.Ordering, fc.Ordering",
2448+
ORDER BY COALESCE(fcg.Ordering,99999), fc.Ordering",
24372449
new { frameworkId, frameworkCompetencyIds }
24382450
).ToList();
24392451
}
2452+
2453+
public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
2454+
{
2455+
return connection.Query<int>(
2456+
@"SELECT MAX(ID) FROM FrameworkCompetencyGroups
2457+
WHERE FrameworkID = @frameworkId AND CompetencyGroupID = @competencyGroupId",
2458+
new { frameworkId, competencyGroupId }
2459+
).Single();
2460+
}
24402461
}
24412462
}

DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ public bool RemoveSupervisorDelegateById(int supervisorDelegateId, int delegateU
547547
WHERE cas.SupervisorDelegateId = @supervisorDelegateId AND cas.Removed IS NULL AND sarsv.Verified IS NULL", new { supervisorDelegateId }
548548
);
549549

550+
connection.Execute(
551+
@"DELETE FROM casv FROM CandidateAssessmentSupervisorVerifications casv INNER JOIN
552+
CandidateAssessmentSupervisors cas ON casv.CandidateAssessmentSupervisorID = cas.ID
553+
WHERE cas.SupervisorDelegateId = @supervisorDelegateId
554+
AND casv.Verified IS NULL AND casv.SignedOff = 0", new { supervisorDelegateId }
555+
);
556+
550557
var numberOfAffectedRows = connection.Execute(
551558
@"UPDATE SupervisorDelegates SET Removed = getUTCDate()
552559
WHERE ID = @supervisorDelegateId AND Removed IS NULL AND (DelegateUserID = @delegateUserId OR SupervisorAdminID = @adminId)",

DigitalLearningSolutions.Web/Controllers/FrameworksController/Frameworks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ public IActionResult ViewFramework(string tabname, int frameworkId, int? framewo
718718
}
719719

720720
[Route("/Framework/{frameworkId}/Structure/PrintLayout")]
721-
public IActionResult PrintLayout(int frameworkId) {
721+
public IActionResult PrintLayout(int frameworkId)
722+
{
722723
var adminId = GetAdminId();
723724
var detailFramework = frameworkService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
724725
var routeData = new Dictionary<string, string> { { "frameworkId", detailFramework?.ID.ToString() } };

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ public IActionResult DownloadCompetencies(int frameworkId, int DownloadOption, s
4545
public IActionResult StartImport(ImportCompetenciesFormData model, int frameworkId, string tabname, bool isNotBlank)
4646
{
4747
if (!ModelState.IsValid)
48-
return View("Developer/Import/Index", model);
48+
{
49+
var adminId = GetAdminId();
50+
var framework = frameworkService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
51+
var viewModel = new ImportCompetenciesViewModel(framework, isNotBlank);
52+
viewModel.ImportFile = model.ImportFile;
53+
return View("Developer/Import/Index", viewModel);
54+
}
4955
try
5056
{
5157
var adminUserID = User.GetAdminIdKnownNotNull();
@@ -73,7 +79,7 @@ public IActionResult StartImport(ImportCompetenciesFormData model, int framework
7379
}
7480
catch (InvalidHeadersException)
7581
{
76-
return View("Developer/Import/ImportFailed");
82+
return RedirectToAction("ImportFailed", "Frameworks", new { frameworkId, tabname, isNotBlank });
7783
}
7884
}
7985
[Route("/Framework/{frameworkId}/{tabname}/Import/Uploaded")]
@@ -97,9 +103,18 @@ public IActionResult ImportCompleted()
97103
catch (InvalidHeadersException)
98104
{
99105
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
100-
return View("Developer/Import/ImportFailed");
106+
return RedirectToAction("ImportFailed", "Frameworks", new { data.FrameworkId, tabname = "Structure", data.IsNotBlank });
101107
}
102108
}
109+
[Route("/Framework/{frameworkId}/{tabname}/Import/Failed")]
110+
public IActionResult ImportFailed(int frameworkId, string tabname, bool isNotBlank)
111+
{
112+
var adminId = GetAdminId();
113+
var framework = frameworkService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
114+
var viewModel = new ImportCompetenciesViewModel(framework, isNotBlank);
115+
return View("Developer/Import/ImportFailed", viewModel);
116+
}
117+
103118
[Route("/Framework/{frameworkId}/{tabname}/Import/Ordering")]
104119
public IActionResult ApplyCompetencyOrdering()
105120
{
@@ -200,7 +215,7 @@ public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model
200215
public IActionResult AddQuestionsToWhichCompetencies()
201216
{
202217
var data = GetBulkUploadData();
203-
if (data.DefaultQuestionIDs.Count ==0 && data.CustomAssessmentQuestionID == null)
218+
if (data.DefaultQuestionIDs.Count == 0 && data.CustomAssessmentQuestionID == null)
204219
{
205220
return RedirectToAction("ImportSummary", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
206221
}
@@ -267,7 +282,10 @@ public IActionResult CancelImport()
267282
{
268283
var data = GetBulkUploadData();
269284
var frameworkId = data.FrameworkId;
270-
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
285+
if (!string.IsNullOrWhiteSpace(data.CompetenciesFileName))
286+
{
287+
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
288+
}
271289
TempData.Clear();
272290
return RedirectToAction("ViewFramework", new { frameworkId, tabname = "Structure" });
273291
}

DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c
3232
public bool AddCustomAssessmentQuestion { get; set; } = false;
3333
public List<int> DefaultQuestionIDs { get; set; } = [];
3434
public int? CustomAssessmentQuestionID { get; set; }
35-
public int AddAssessmentQuestionsOption { get; set; } //1 = only added, 2 = added and updated, 3 = all uploaded
35+
public int AddAssessmentQuestionsOption { get; set; } = 1; //1 = only added, 2 = added and updated, 3 = all uploaded
3636
public int CompetenciesToProcessCount { get; set; }
3737
public int CompetenciesToAddCount { get; set; }
3838
public int CompetenciesToUpdateCount { get; set; }

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public interface IFrameworkService
5858
int GetMaxFrameworkCompetencyGroupID();
5959
IEnumerable<BulkCompetency> GetBulkCompetenciesForFramework(int frameworkId);
6060
List<int> GetFrameworkCompetencyOrder(int frameworkId, List<int> frameworkCompetencyIds);
61+
int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId);
6162

6263
// Assessment questions:
6364
IEnumerable<AssessmentQuestion> GetAllCompetencyQuestions(int adminId);
@@ -192,7 +193,7 @@ int adminId
192193

193194
void UpdateFrameworkConfig(int frameworkId, int adminId, string? frameworkConfig);
194195

195-
void UpdateFrameworkCompetencyGroup(
196+
bool UpdateFrameworkCompetencyGroup(
196197
int frameworkCompetencyGroupId,
197198
int competencyGroupId,
198199
string name,
@@ -674,13 +675,13 @@ public int UpdateCompetencyFlags(int frameworkId, int competencyId, int[] select
674675
}
675676

676677
public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId, bool? alwaysShowDescription)
677-
{
678+
{
678679
frameworkDataService.UpdateFrameworkCompetency(frameworkCompetencyId, name, description, adminId, alwaysShowDescription);
679680
}
680681

681-
public void UpdateFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, string name, string? description, int adminId)
682+
public bool UpdateFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, string name, string? description, int adminId)
682683
{
683-
frameworkDataService.UpdateFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, name, description, adminId);
684+
return frameworkDataService.UpdateFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, name, description, adminId);
684685
}
685686

686687
public void UpdateFrameworkConfig(int frameworkId, int adminId, string? frameworkConfig)
@@ -717,5 +718,10 @@ public void UpdateReviewRequestedDate(int reviewId)
717718
{
718719
frameworkDataService.UpdateReviewRequestedDate(reviewId);
719720
}
721+
722+
public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
723+
{
724+
return frameworkDataService.GetFrameworkCompetencyGroupId(frameworkId, competencyGroupId);
725+
}
720726
}
721727
}

0 commit comments

Comments
 (0)