Skip to content

Commit 0c8f5ba

Browse files
committed
TD-5163 Process imported competencies
1 parent 8a6cb20 commit 0c8f5ba

File tree

6 files changed

+132
-39
lines changed

6 files changed

+132
-39
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ bool zeroBased
131131

132132
int InsertCompetency(string name, string? description, int adminId);
133133

134-
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId);
134+
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false);
135135

136136
int AddCollaboratorToFramework(int frameworkId, string userEmail, bool canModify);
137-
void AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass);
137+
int AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass);
138138
void UpdateFrameworkCustomFlag(int frameworkId, int id, string flagName, string flagGroup, string flagTagClass);
139139

140140
void AddFrameworkDefaultQuestion(int frameworkId, int assessmentQuestionId, int adminId, bool addToExisting);
@@ -205,7 +205,7 @@ void UpdateFrameworkCompetencyGroup(
205205
int adminId
206206
);
207207

208-
void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId);
208+
void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId, bool? alwaysShowDescription);
209209
void UpdateCompetencyFlags(int frameworkId, int competencyId, int[] selectedFlagIds);
210210

211211
void MoveFrameworkCompetencyGroup(int frameworkCompetencyGroupId, bool singleStep, string direction);
@@ -656,7 +656,8 @@ public int InsertFrameworkCompetency(
656656
int competencyId,
657657
int? frameworkCompetencyGroupID,
658658
int adminId,
659-
int frameworkId
659+
int frameworkId,
660+
bool alwaysShowDescription = false
660661
)
661662
{
662663
if ((competencyId < 1) | (adminId < 1) | (frameworkId < 1))
@@ -978,7 +979,7 @@ FROM FrameworkCompetencyGroups AS fcg
978979
public FrameworkCompetency? GetFrameworkCompetencyById(int Id)
979980
{
980981
return connection.QueryFirstOrDefault<FrameworkCompetency>(
981-
@"SELECT fc.ID, c.ID AS CompetencyID, c.Name, c.Description, fc.Ordering
982+
@"SELECT fc.ID, c.ID AS CompetencyID, c.Name, c.Description, fc.Ordering, c.AlwaysShowDescription
982983
FROM FrameworkCompetencies AS fc
983984
INNER JOIN Competencies AS c ON fc.CompetencyID = c.ID
984985
WHERE fc.ID = @Id",
@@ -1045,7 +1046,7 @@ int adminId
10451046
}
10461047
}
10471048

1048-
public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId)
1049+
public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId, bool? alwaysShowDescription)
10491050
{
10501051
if ((frameworkCompetencyId < 1) | (adminId < 1) | (name.Length < 3))
10511052
{
@@ -1057,10 +1058,10 @@ public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, st
10571058

10581059
//DO WE NEED SOMETHING IN HERE TO CHECK WHETHER IT IS USED ELSEWHERE AND WARN THE USER?
10591060
var numberOfAffectedRows = connection.Execute(
1060-
@"UPDATE Competencies SET Name = @name, Description = @description, UpdatedByAdminID = @adminId
1061+
@"UPDATE Competencies SET Name = @name, Description = @description, UpdatedByAdminID = @adminId, AlwaysShowDescription = CASE WHEN @alwaysShowDescription IS NULL THEN AlwaysShowDescription ELSE @alwaysShowDescription END
10611062
FROM Competencies INNER JOIN FrameworkCompetencies AS fc ON Competencies.ID = fc.CompetencyID
10621063
WHERE (fc.Id = @frameworkCompetencyId)",
1063-
new { name, description, adminId, frameworkCompetencyId }
1064+
new { name, description, adminId, frameworkCompetencyId, alwaysShowDescription}
10641065
);
10651066
if (numberOfAffectedRows < 1)
10661067
{
@@ -1094,11 +1095,12 @@ SELECT FlagID FROM CompetencyFlags
10941095
new { competencyId, frameworkId });
10951096
}
10961097

1097-
public void AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass)
1098+
public int AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass)
10981099
{
1099-
connection.Execute(
1100-
@$"INSERT INTO Flags(FrameworkID, FlagName, FlagGroup, FlagTagClass)
1101-
VALUES(@frameworkId, @flagName, @flagGroup, @flagTagClass)",
1100+
return connection.QuerySingle<int>(
1101+
@"INSERT INTO Flags(FrameworkID, FlagName, FlagGroup, FlagTagClass)
1102+
OUTPUT INSERTED.ID
1103+
VALUES(@frameworkId, @flagName, @flagGroup, @flagTagClass);",
11021104
new { frameworkId, flagName, flagGroup, flagTagClass });
11031105
}
11041106

DigitalLearningSolutions.Data/Models/Frameworks/FrameworkCompetency.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class FrameworkCompetency : BaseSearchableItem
1414
public int AssessmentQuestions { get; set; }
1515
public int CompetencyLearningResourcesCount { get; set; }
1616
public string? FrameworkName { get; set; }
17+
public bool? AlwaysShowDescription { get; set; }
1718

1819
public override string SearchableName
1920
{

DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ public IActionResult ImportSummary()
224224
var model = new ImportSummaryViewModel(data);
225225
return View("Developer/Import/ImportSummary", model);
226226
}
227+
[HttpPost]
228+
[Route("/Framework/{frameworkId}/{tabname}/Import/Summary")]
229+
public IActionResult ImportSummarySubmit()
230+
{
231+
var data = GetBulkUploadData();
232+
var adminId = GetAdminId();
233+
var uploadDir = Path.Combine(webHostEnvironment.WebRootPath, "Uploads\\");
234+
var filePath = Path.Combine(uploadDir, data.CompetenciesFileName);
235+
var workbook = new XLWorkbook(filePath);
236+
var results = importCompetenciesFromFileService.ProcessCompetenciesFromFile(workbook, adminId, data.FrameworkId, data.FrameworkVocubulary, data.ReorderCompetenciesOption, data.AddAssessmentQuestionsOption, data.AddCustomAssessmentQuestion ? (int)data.CustomAssessmentQuestionID : 0, data.AddDefaultAssessmentQuestions ? data.DefaultQuestionIDs : []);
237+
data.ImportCompetenciesResult = results;
238+
setBulkUploadData(data);
239+
return RedirectToAction("UploadResults", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName });
240+
}
227241
[Route("CancelImport")]
228242
public IActionResult CancelImport()
229243
{

DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DigitalLearningSolutions.Data.Models.Frameworks;
2+
using DigitalLearningSolutions.Data.Models.Frameworks.Import;
23
using System.Collections;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -42,5 +43,6 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c
4243
public int SubtotalCompetenciesUpdated { get; set; }
4344
public int SubTotalSkipped { get; set; }
4445
public IEnumerable<(int RowNumber, string ErrorMessage)> Errors { get; set; } = Enumerable.Empty<(int, string)>();
46+
public ImportCompetenciesResult ImportCompetenciesResult { get;set;}
4547
}
4648
}

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ bool zeroBased
119119

120120
int InsertCompetencyGroup(string groupName, string? groupDescription, int adminId);
121121

122-
int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId);
122+
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false);
123123

124124
IEnumerable<FrameworkCompetency> GetAllCompetenciesForAdminId(string name, int adminId);
125125

126126
int InsertCompetency(string name, string? description, int adminId);
127127

128-
int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId);
128+
int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId);
129129

130130
int AddCollaboratorToFramework(int frameworkId, string userEmail, bool canModify);
131-
void AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass);
131+
int AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass);
132132
void UpdateFrameworkCustomFlag(int frameworkId, int id, string flagName, string flagGroup, string flagTagClass);
133133

134134
void AddFrameworkDefaultQuestion(int frameworkId, int assessmentQuestionId, int adminId, bool addToExisting);
@@ -199,7 +199,7 @@ void UpdateFrameworkCompetencyGroup(
199199
int adminId
200200
);
201201

202-
void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId);
202+
void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId, bool? alwaysShowDescription = false);
203203
void UpdateCompetencyFlags(int frameworkId, int competencyId, int[] selectedFlagIds);
204204

205205
void MoveFrameworkCompetencyGroup(int frameworkCompetencyGroupId, bool singleStep, string direction);
@@ -277,9 +277,9 @@ public void AddCompetencyAssessmentQuestion(int frameworkCompetencyId, int asses
277277
frameworkDataService.AddCompetencyAssessmentQuestion(frameworkCompetencyId, assessmentQuestionId, adminId);
278278
}
279279

280-
public void AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass)
280+
public int AddCustomFlagToFramework(int frameworkId, string flagName, string flagGroup, string flagTagClass)
281281
{
282-
frameworkDataService.AddCustomFlagToFramework(frameworkId, flagName, flagGroup, flagTagClass);
282+
return frameworkDataService.AddCustomFlagToFramework(frameworkId, flagName, flagGroup, flagTagClass);
283283
}
284284

285285
public void AddFrameworkDefaultQuestion(int frameworkId, int assessmentQuestionId, int adminId, bool addToExisting)
@@ -602,9 +602,9 @@ public int InsertCompetencyGroup(string groupName, string? groupDescription, int
602602
return frameworkDataService.InsertCompetencyGroup(groupName, groupDescription, adminId);
603603
}
604604

605-
public int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId)
605+
public int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false)
606606
{
607-
return frameworkDataService.InsertFrameworkCompetency(competencyId, frameworkCompetencyGroupID, adminId, frameworkId);
607+
return frameworkDataService.InsertFrameworkCompetency(competencyId, frameworkCompetencyGroupID, adminId, frameworkId, alwaysShowDescription);
608608
}
609609

610610
public int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId)
@@ -672,9 +672,9 @@ public void UpdateCompetencyFlags(int frameworkId, int competencyId, int[] selec
672672
return frameworkDataService.UpdateFrameworkBranding(frameworkId, brandId, categoryId, topicId, adminId);
673673
}
674674

675-
public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId)
676-
{
677-
frameworkDataService.UpdateFrameworkCompetency(frameworkCompetencyId, name, description, adminId);
675+
public void UpdateFrameworkCompetency(int frameworkCompetencyId, string name, string? description, int adminId, bool? alwaysShowDescription)
676+
{
677+
frameworkDataService.UpdateFrameworkCompetency(frameworkCompetencyId, name, description, adminId, alwaysShowDescription);
678678
}
679679

680680
public void UpdateFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, string name, string? description, int adminId)

0 commit comments

Comments
 (0)