Skip to content

Commit 358a7bf

Browse files
committed
TD-5153 Fixes update of competency description and import failed navigation
1 parent 30426fb commit 358a7bf

File tree

8 files changed

+54
-40
lines changed

8 files changed

+54
-40
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 14 additions & 4 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);
@@ -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

@@ -1005,7 +1006,7 @@ int adminId
10051006
SET CompetencyGroupID = @newCompetencyGroupId, UpdatedByAdminID = @adminId
10061007
WHERE ID = @frameworkCompetencyGroupId",
10071008
new { newCompetencyGroupId, adminId, frameworkCompetencyGroupId }
1008-
1009+
10091010
);
10101011
if (numberOfAffectedRows < 1)
10111012
{
@@ -1058,7 +1059,7 @@ public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, st
10581059
@"UPDATE Competencies SET Name = @name, Description = @description, UpdatedByAdminID = @adminId, AlwaysShowDescription = CASE WHEN @alwaysShowDescription IS NULL THEN AlwaysShowDescription ELSE @alwaysShowDescription END
10591060
FROM Competencies INNER JOIN FrameworkCompetencies AS fc ON Competencies.ID = fc.CompetencyID
10601061
WHERE (fc.Id = @frameworkCompetencyId)",
1061-
new { name, description, adminId, frameworkCompetencyId, alwaysShowDescription}
1062+
new { name, description, adminId, frameworkCompetencyId, alwaysShowDescription }
10621063
);
10631064
if (numberOfAffectedRows < 1)
10641065
{
@@ -2448,5 +2449,14 @@ FROM FrameworkCompetencies AS fc INNER JOIN
24482449
new { frameworkId, frameworkCompetencyIds }
24492450
).ToList();
24502451
}
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+
}
24512461
}
24522462
}

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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public IActionResult StartImport(ImportCompetenciesFormData model, int framework
7979
}
8080
catch (InvalidHeadersException)
8181
{
82-
return View("Developer/Import/ImportFailed");
82+
return RedirectToAction("ImportFailed", "Frameworks", new { frameworkId, tabname, isNotBlank });
8383
}
8484
}
8585
[Route("/Framework/{frameworkId}/{tabname}/Import/Uploaded")]
@@ -103,9 +103,18 @@ public IActionResult ImportCompleted()
103103
catch (InvalidHeadersException)
104104
{
105105
FileHelper.DeleteFile(webHostEnvironment, data.CompetenciesFileName);
106-
return View("Developer/Import/ImportFailed");
106+
return RedirectToAction("ImportFailed", "Frameworks", new { data.FrameworkId, tabname = "Structure", data.IsNotBlank });
107107
}
108108
}
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+
109118
[Route("/Framework/{frameworkId}/{tabname}/Import/Ordering")]
110119
public IActionResult ApplyCompetencyOrdering()
111120
{
@@ -206,7 +215,7 @@ public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model
206215
public IActionResult AddQuestionsToWhichCompetencies()
207216
{
208217
var data = GetBulkUploadData();
209-
if (data.DefaultQuestionIDs.Count ==0 && data.CustomAssessmentQuestionID == null)
218+
if (data.DefaultQuestionIDs.Count == 0 && data.CustomAssessmentQuestionID == null)
210219
{
211220
return RedirectToAction("ImportSummary", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
212221
}

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public int UpdateCompetencyFlags(int frameworkId, int competencyId, int[] select
675675
}
676676

677677
public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId, bool? alwaysShowDescription)
678-
{
678+
{
679679
frameworkDataService.UpdateFrameworkCompetency(frameworkCompetencyId, name, description, adminId, alwaysShowDescription);
680680
}
681681

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ namespace DigitalLearningSolutions.Web.Services
1111
using ClosedXML.Excel;
1212
using DigitalLearningSolutions.Data.Exceptions;
1313
using DigitalLearningSolutions.Data.Helpers;
14-
using DigitalLearningSolutions.Data.Models.Frameworks;
1514
using DigitalLearningSolutions.Data.Models.Frameworks.Import;
16-
using DocumentFormat.OpenXml.Office2010.Excel;
1715

1816
public interface IImportCompetenciesFromFileService
1917
{
2018
byte[] GetCompetencyFileForFramework(int frameworkId, bool isBlank, string vocabulary);
2119
public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook, string vocabulary, int frameworkId);
22-
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminUserId, int frameworkId, string vocabulary, int reorderCompetenciesOption, int addAssessmentQuestionsOption, int customAssessmentQuestionID, List<int> defaultQuestionIds);
20+
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminId, int frameworkId, string vocabulary, int reorderCompetenciesOption, int addAssessmentQuestionsOption, int customAssessmentQuestionID, List<int> defaultQuestionIds);
2321
}
2422
public class ImportCompetenciesFromFileService : IImportCompetenciesFromFileService
2523
{
@@ -70,12 +68,12 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int>
7068
}
7169
competencyRow.Validate();
7270
}
73-
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminUserId, int frameworkId, string vocabulary, int reorderCompetenciesOption, int addAssessmentQuestionsOption, int customAssessmentQuestionID, List<int> defaultQuestionIds)
71+
public ImportCompetenciesResult ProcessCompetenciesFromFile(IXLWorkbook workbook, int adminId, int frameworkId, string vocabulary, int reorderCompetenciesOption, int addAssessmentQuestionsOption, int customAssessmentQuestionID, List<int> defaultQuestionIds)
7472
{
7573
int maxFrameworkCompetencyId = frameworkService.GetMaxFrameworkCompetencyID();
7674
int maxFrameworkCompetencyGroupId = frameworkService.GetMaxFrameworkCompetencyGroupID();
7775
var table = OpenCompetenciesTable(workbook, vocabulary);
78-
return ProcessCompetenciesTable(table, adminUserId, frameworkId, maxFrameworkCompetencyId, maxFrameworkCompetencyGroupId, addAssessmentQuestionsOption, reorderCompetenciesOption, customAssessmentQuestionID, defaultQuestionIds);
76+
return ProcessCompetenciesTable(table, adminId, frameworkId, maxFrameworkCompetencyId, maxFrameworkCompetencyGroupId, addAssessmentQuestionsOption, reorderCompetenciesOption, customAssessmentQuestionID, defaultQuestionIds);
7977
}
8078
internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook, string vocabulary)
8179
{
@@ -92,7 +90,7 @@ internal IXLTable OpenCompetenciesTable(IXLWorkbook workbook, string vocabulary)
9290
}
9391
return table;
9492
}
95-
internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int adminUserId, int frameworkId, int maxFrameworkCompetencyId, int maxFrameworkCompetencyGroupId, int addAssessmentQuestionsOption, int reorderCompetenciesOption, int customAssessmentQuestionID, List<int> defaultQuestionIds)
93+
internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int adminId, int frameworkId, int maxFrameworkCompetencyId, int maxFrameworkCompetencyGroupId, int addAssessmentQuestionsOption, int reorderCompetenciesOption, int customAssessmentQuestionID, List<int> defaultQuestionIds)
9694
{
9795
var competenciesRows = table.Rows().Skip(1).Select(row => new CompetencyTableRow(table, row)).ToList();
9896
int rowCount = 0;
@@ -120,7 +118,7 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
120118
.Count();
121119
foreach (var competencyRow in competenciesRows)
122120
{
123-
maxFrameworkCompetencyGroupId = ProcessCompetencyRow(adminUserId, frameworkId, maxFrameworkCompetencyId, maxFrameworkCompetencyGroupId, addAssessmentQuestionsOption, reorderCompetenciesOption, customAssessmentQuestionID, defaultQuestionIds, competencyRow);
121+
maxFrameworkCompetencyGroupId = ProcessCompetencyRow(adminId, frameworkId, maxFrameworkCompetencyId, maxFrameworkCompetencyGroupId, addAssessmentQuestionsOption, reorderCompetenciesOption, customAssessmentQuestionID, defaultQuestionIds, competencyRow);
124122
}
125123
// Check for changes to competency group order and apply them if appropriate:
126124
if (reorderCompetenciesOption == 2)
@@ -135,7 +133,7 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
135133
var existingGroups = frameworkService.GetFrameworkCompetencyGroups(frameworkId).Select(row => new { row.ID, row.Name })
136134
.Distinct()
137135
.ToList();
138-
var placesToMove = Math.Abs(existingGroups.FindIndex(group => group.Name == distinctCompetencyGroups[i])-i);
136+
var placesToMove = Math.Abs(existingGroups.FindIndex(group => group.Name == distinctCompetencyGroups[i]) - i);
139137
if (placesToMove > 0)
140138
{
141139
var thisGroup = existingGroups.FirstOrDefault(group => group.Name == distinctCompetencyGroups[i]);
@@ -154,7 +152,7 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
154152
return new ImportCompetenciesResult(competenciesRows);
155153
}
156154
private int ProcessCompetencyRow(
157-
int adminUserId,
155+
int adminId,
158156
int frameworkId,
159157
int maxFrameworkCompetencyId,
160158
int maxFrameworkCompetencyGroupId,
@@ -175,27 +173,22 @@ CompetencyTableRow competencyRow
175173
int? frameworkCompetencyGroupId = null;
176174
if (competencyRow.CompetencyGroup != null)
177175
{
178-
int newCompetencyGroupId = frameworkService.InsertCompetencyGroup(competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminUserId, frameworkId);
176+
int newCompetencyGroupId = frameworkService.InsertCompetencyGroup(competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminId, frameworkId);
179177
if (newCompetencyGroupId > 0)
180178
{
181-
frameworkCompetencyGroupId = frameworkService.InsertFrameworkCompetencyGroup(newCompetencyGroupId, frameworkId, adminUserId);
179+
frameworkCompetencyGroupId = frameworkService.InsertFrameworkCompetencyGroup(newCompetencyGroupId, frameworkId, adminId);
182180
if (frameworkCompetencyGroupId > maxFrameworkCompetencyGroupId)
183181
{
184182
maxFrameworkCompetencyGroupId = (int)frameworkCompetencyGroupId;
185183
competencyRow.RowStatus = RowStatus.CompetencyGroupInserted;
186184
}
187185
else
188186
{
189-
//TO DO: Need to get frameworkCompetencyGroupId and check admin ID
190187
frameworkCompetencyGroupId = frameworkService.GetFrameworkCompetencyGroupId(frameworkId, newCompetencyGroupId);
191-
var isUpdated = frameworkService.UpdateFrameworkCompetencyGroup((int)frameworkCompetencyGroupId, newCompetencyGroupId, competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminUserId);
188+
var isUpdated = frameworkService.UpdateFrameworkCompetencyGroup((int)frameworkCompetencyGroupId, newCompetencyGroupId, competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminId);
192189
competencyRow.RowStatus = RowStatus.CompetencyGroupUpdated;
193190
}
194191
}
195-
else
196-
{
197-
198-
}
199192
}
200193
// If FrameworkCompetency ID is supplied, update the competency
201194
if (competencyRow.ID != null)
@@ -206,7 +199,7 @@ CompetencyTableRow competencyRow
206199
newCompetencyId = frameworkCompetency.CompetencyID;
207200
if (frameworkCompetency.Name != competencyRow.Competency || frameworkCompetency.Description != competencyRow.CompetencyDescription || frameworkCompetency.AlwaysShowDescription != competencyRow.AlwaysShowDescription)
208201
{
209-
frameworkService.UpdateFrameworkCompetency((int)competencyRow.ID, competencyRow.Competency, competencyRow.CompetencyDescription, adminUserId, competencyRow.AlwaysShowDescription ?? false);
202+
frameworkService.UpdateFrameworkCompetency((int)competencyRow.ID, competencyRow.Competency, competencyRow.CompetencyDescription, adminId, competencyRow.AlwaysShowDescription ?? false);
210203
competencyRow.RowStatus = (competencyRow.RowStatus == RowStatus.CompetencyGroupInserted ? RowStatus.CompetencyGroupAndCompetencyUpdated : RowStatus.CompetencyUpdated);
211204
}
212205
else
@@ -218,10 +211,10 @@ CompetencyTableRow competencyRow
218211
else
219212
{
220213
//Check if competency already exists in framework competency group and add if not
221-
newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminUserId);
214+
newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminId);
222215
if (newCompetencyId > 0)
223216
{
224-
newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminUserId, frameworkId, competencyRow.AlwaysShowDescription ?? false); //including always show desc flag
217+
newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId, competencyRow.AlwaysShowDescription ?? false); //including always show desc flag
225218
if (newFrameworkCompetencyId > maxFrameworkCompetencyId)
226219
{
227220
competencyRow.RowStatus = (competencyRow.RowStatus == RowStatus.CompetencyGroupInserted ? RowStatus.CompetencyGroupAndCompetencyInserted : RowStatus.CompetencyInserted);
@@ -297,16 +290,16 @@ CompetencyTableRow competencyRow
297290
{
298291
foreach (var id in defaultQuestionIds)
299292
{
300-
frameworkService.AddCompetencyAssessmentQuestion(competencyRow.ID ?? newFrameworkCompetencyId, id, adminUserId);
293+
frameworkService.AddCompetencyAssessmentQuestion(competencyRow.ID ?? newFrameworkCompetencyId, id, adminId);
301294
}
302295
if (customAssessmentQuestionID > 0)
303296
{
304-
frameworkService.AddCompetencyAssessmentQuestion(competencyRow.ID ?? newFrameworkCompetencyId, customAssessmentQuestionID, adminUserId);
297+
frameworkService.AddCompetencyAssessmentQuestion(competencyRow.ID ?? newFrameworkCompetencyId, customAssessmentQuestionID, adminId);
305298
}
306299
}
307300
}
308301

309-
302+
310303

311304
return maxFrameworkCompetencyGroupId;
312305
}

DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/ImportFailed.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
@using DigitalLearningSolutions.Web.Extensions
33
@using DigitalLearningSolutions.Web.ViewModels.Frameworks.Import
44
@using Microsoft.Extensions.Configuration
5-
@model ImportCompetenciesResultsViewModel
5+
@model ImportCompetenciesViewModel
66
@{
77
ViewData["Title"] = "Framework - Import Failed";
88
ViewData["Application"] = "Framework Service";
99
ViewData["HeaderPathName"] = "Framework Service";
1010
var errorHasOccurred = !ViewData.ModelState.IsValid;
1111
var cancelLinkData = Html.GetRouteValues();
12+
cancelLinkData.Add("IsNotBlank", Model.IsNotBlank.ToString());
1213
}
1314
<link rel="stylesheet" href="@Url.Content("~/css/frameworks/frameworksShared.css")" asp-append-version="true">
1415
@section NavMenuItems {
@@ -35,7 +36,7 @@
3536
The file that you uploaded either does not have the correct column headers on the first row or is not formatted as a table.
3637
</p>
3738

38-
<p class="nhsuk-body-m">Refer to the instructions on the Import Competencies page to make sure your Excel file has the correct column headers.</p>
39+
<p class="nhsuk-body-m">Refer to the instructions on the Import @Model.FrameworkVocabularyPlural page to make sure your Excel file has the correct column headers.</p>
3940

4041
<vc:action-link asp-controller="Frameworks" asp-action="ViewFramework" asp-all-route-data="@cancelLinkData" link-text="Back to framework structure" />
4142

DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/Index.cshtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{
3737
<partial name="Shared/_PublishedWarning" />
3838
}
39-
39+
4040
<div class="nhsuk-form-group">
4141
@if (Model.IsNotBlank)
4242
{
@@ -45,14 +45,14 @@
4545
<p>
4646
Bulk upload <strong>cannot</strong> be used to:
4747
</p>
48-
<ul>
48+
<ul>
4949
<li>Delete @Model.FrameworkVocabularyPlural.ToLower() or @Model.FrameworkVocabularySingular.ToLower() groups</li>
5050
<li>Remove assessment questions from existing @Model.FrameworkVocabularyPlural.ToLower()</li>
5151
<li>Add more than one custom assessment question to uploaded @Model.FrameworkVocabularyPlural.ToLower()</li>
5252
<li>Remove flags from @Model.FrameworkVocabularyPlural.ToLower()</li>
5353
<li>Add or edit empty @Model.FrameworkVocabularyPlural.ToLower() groups</li>
54-
</ul>
55-
54+
</ul>
55+
5656
</div>
5757
<p class="nhsuk-body-m">
5858
To bulk add and/or update @Model.FrameworkVocabularyPlural.ToLower() in the framework, <strong>@Model.FrameworkName</strong>, download an Excel workbook using one of the options below.

0 commit comments

Comments
 (0)