Skip to content

Commit 810fd8e

Browse files
committed
TD-5163 Implements the upload results view
1 parent a7c338f commit 810fd8e

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,13 @@ public void AddCompetencyAssessmentQuestion(int frameworkCompetencyId, int asses
15161516
FROM [CompetencyAssessmentQuestions]
15171517
WHERE ([CompetencyId] = fc.CompetencyID)), 0)+1
15181518
FROM FrameworkCompetencies AS fc
1519-
WHERE Id = @frameworkCompetencyId",
1519+
WHERE Id = @frameworkCompetencyId
1520+
AND NOT EXISTS (
1521+
SELECT 1
1522+
FROM CompetencyAssessmentQuestions AS caq
1523+
WHERE caq.CompetencyId = fc.CompetencyID
1524+
AND caq.AssessmentQuestionID = @assessmentQuestionId
1525+
);",
15201526
new { frameworkCompetencyId, assessmentQuestionId }
15211527
);
15221528
if (numberOfAffectedRows < 1)

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,21 @@ public IActionResult ImportSummarySubmit()
235235
var workbook = new XLWorkbook(filePath);
236236
var results = importCompetenciesFromFileService.ProcessCompetenciesFromFile(workbook, adminId, data.FrameworkId, data.FrameworkVocubulary, data.ReorderCompetenciesOption, data.AddAssessmentQuestionsOption, data.AddCustomAssessmentQuestion ? (int)data.CustomAssessmentQuestionID : 0, data.AddDefaultAssessmentQuestions ? data.DefaultQuestionIDs : []);
237237
data.ImportCompetenciesResult = results;
238+
//TO DO apply ordering changes if required:
239+
if (data.ReorderCompetenciesOption == 2 && data.CompetenciesToReorderCount > 0)
240+
{
241+
242+
}
238243
setBulkUploadData(data);
239244
return RedirectToAction("UploadResults", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
240245
}
246+
[Route("/Framework/{frameworkId}/{tabname}/Import/Results")]
247+
public IActionResult UploadResults()
248+
{
249+
var data = GetBulkUploadData();
250+
var model = new ImportCompetenciesResultsViewModel(data.ImportCompetenciesResult, data.FrameworkId, data.FrameworkName, data.FrameworkVocubulary);
251+
return View("Developer/Import/UploadResults", model);
252+
}
241253
[Route("CancelImport")]
242254
public IActionResult CancelImport()
243255
{

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ CompetencyTableRow competencyRow
127127
}
128128
int newCompetencyGroupId = 0;
129129
int newCompetencyId = 0;
130+
int newFrameworkCompetencyId = 0;
130131
//If competency group is set, check if competency group exists within framework and add if not and get the Framework Competency Group ID
131132
int ? frameworkCompetencyGroupId = null;
132133
if (competencyRow.CompetencyGroup != null)
@@ -166,7 +167,7 @@ CompetencyTableRow competencyRow
166167
newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminUserId);
167168
if (newCompetencyId > 0)
168169
{
169-
var newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminUserId, frameworkId, competencyRow.AlwaysShowDescription ?? false); //including always show desc flag
170+
newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminUserId, frameworkId, competencyRow.AlwaysShowDescription ?? false); //including always show desc flag
170171
if (newFrameworkCompetencyId > maxFrameworkCompetencyId)
171172
{
172173
competencyRow.RowStatus = (competencyRow.RowStatus == RowStatus.CompetencyGroupInserted ? RowStatus.CompetencyGroupAndCompetencyInserted : RowStatus.CompetencyInserted);
@@ -216,11 +217,11 @@ CompetencyTableRow competencyRow
216217
{
217218
foreach(var id in defaultQuestionIds)
218219
{
219-
frameworkService.AddCompetencyAssessmentQuestion((int)competencyRow.ID, id, adminUserId);
220+
frameworkService.AddCompetencyAssessmentQuestion(competencyRow.ID ?? newFrameworkCompetencyId, id, adminUserId);
220221
}
221222
if(customAssessmentQuestionID > 0)
222223
{
223-
frameworkService.AddCompetencyAssessmentQuestion((int)competencyRow.ID, customAssessmentQuestionID, adminUserId);
224+
frameworkService.AddCompetencyAssessmentQuestion(competencyRow.ID ?? newFrameworkCompetencyId, customAssessmentQuestionID, adminUserId);
224225
}
225226
}
226227
}

DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/ImportCompetenciesResultsViewModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import
22
{
33
using DigitalLearningSolutions.Data.Models.Frameworks.Import;
4+
using DigitalLearningSolutions.Web.Helpers;
45
using System.Collections.Generic;
56
using System.Linq;
67

78
public class ImportCompetenciesResultsViewModel
89
{
9-
public ImportCompetenciesResultsViewModel(ImportCompetenciesResult importCompetenciesResult)
10+
public ImportCompetenciesResultsViewModel(ImportCompetenciesResult importCompetenciesResult, int frameworkId, string frameworkName, string frameworkVocabulary)
1011
{
1112
ProcessedCount = importCompetenciesResult.ProcessedCount;
1213
CompetenciesInsertedCount = importCompetenciesResult.CompetencyAddedCount;
14+
CompetenciesUpdatedCount = importCompetenciesResult.CompetencyUpdatedCount;
1315
CompetencyGroupsInsertedCount = importCompetenciesResult.GroupAddedCount;
16+
CompetencyGroupsUpdatedCount = importCompetenciesResult.GroupUpdatedCount;
1417
SkippedCount = importCompetenciesResult.SkippedCount;
1518
Errors = importCompetenciesResult.Errors.Select(x => (x.RowNumber, MapReasonToErrorMessage(x.Reason)));
19+
FrameworkID = frameworkId;
20+
FrameworkName = frameworkName;
21+
FrameworkVocabularySingular = FrameworkVocabularyHelper.VocabularySingular(frameworkVocabulary);
22+
FrameworkVocabularyPlural = FrameworkVocabularyHelper.VocabularyPlural(frameworkVocabulary);
1623
}
1724
public IEnumerable<(int RowNumber, string ErrorMessage)> Errors { get; set; }
1825
public int ErrorCount => Errors.Count();
1926
public int ProcessedCount { get; set; }
2027
public int CompetenciesInsertedCount { get; set; }
28+
public int CompetenciesUpdatedCount { get; set; }
2129
public int CompetencyGroupsInsertedCount { get; set; }
30+
public int CompetencyGroupsUpdatedCount { get; set; }
2231
public int SkippedCount { get; set; }
32+
public int FrameworkID { get; set; }
33+
public string FrameworkName { get; set; }
34+
public string FrameworkVocabularySingular { get; set; }
35+
public string FrameworkVocabularyPlural { get; set; }
2336
private string MapReasonToErrorMessage(ImportCompetenciesResult.ErrorReason reason)
2437
{
2538
return reason switch

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<span class="nhsuk-u-visually-hidden">Important: </span>
102102
<p>Once @Model.FrameworkVocabularySingular.ToLower() records are processed, changes cannot be undone.</p>
103103
</div>
104-
<form asp-action="StartProcessing">
104+
<form method="post">
105105
<a asp-controller="Frameworks" asp-all-route-data="@cancelLinkData" asp-action="AddQuestionsToWhichCompetencies" role="button" class="nhsuk-button nhsuk-button--secondary">Back</a>
106106
<button type="submit" class="nhsuk-button">Process @Model.FrameworkVocabularyPlural.ToLower()</button>
107107
</form>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
<h2>Summary of results:</h2>
3535
<ul>
3636
<li>@Model.ProcessedCount @(Model.ProcessedCount == 1 ? "line" : "lines") processed</li>
37-
<li>@Model.CompetencyGroupsInsertedCount new @(Model.CompetencyGroupsInsertedCount == 1 ? "competency group" : "competency groups") inserted</li>
38-
<li>@Model.CompetenciesInsertedCount new @(Model.CompetenciesInsertedCount == 1 ? "competency" : "competencies") inserted</li>
39-
<li>@Model.SkippedCount rows @(Model.SkippedCount == 1 ? "record" : "records") skipped (nothing inserted but no errors)</li>
37+
<li>@Model.CompetencyGroupsInsertedCount new @(Model.CompetencyGroupsInsertedCount == 1 ? $"{Model.FrameworkVocabularySingular.ToLower()} group" : $"{Model.FrameworkVocabularySingular.ToLower()} groups") inserted</li>
38+
<li>@Model.CompetenciesInsertedCount new @(Model.CompetenciesInsertedCount == 1 ? Model.FrameworkVocabularySingular.ToLower() : Model.FrameworkVocabularyPlural.ToLower()) inserted</li>
39+
<li>@Model.CompetenciesUpdatedCount new @(Model.CompetenciesUpdatedCount == 1 ? Model.FrameworkVocabularySingular.ToLower() : Model.FrameworkVocabularyPlural.ToLower()) updated</li>
40+
<li>@Model.SkippedCount rows @(Model.SkippedCount == 1 ? "line" : "lines") skipped (nothing inserted but no errors)</li>
4041
<li>@Model.ErrorCount @(Model.ErrorCount == 1 ? "line" : "lines") skipped due to errors</li>
4142
</ul>
4243

0 commit comments

Comments
 (0)