Skip to content

Commit c31cb04

Browse files
authored
Merge pull request #3177 from TechnologyEnhancedLearning/TD-5153-FixTestingFails
TD-5153 fix testing fails for competency upload
2 parents 53f1ba0 + 358a7bf commit c31cb04

File tree

12 files changed

+120
-63
lines changed

12 files changed

+120
-63
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 32 additions & 11 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;
10151018
}
1019+
else
1020+
{
1021+
return true;
1022+
}
1023+
}
1024+
else
1025+
{
1026+
return false;
10161027
}
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
{
@@ -2437,5 +2449,14 @@ FROM FrameworkCompetencies AS fc INNER JOIN
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.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/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)