Skip to content

Commit 5349926

Browse files
authored
Merge pull request #3212 from TechnologyEnhancedLearning/Develop/Fixes/TD-5158-FixGroupUpdates
TD-5158 Fixes committing updates to competency groups during bulk upload
2 parents fcaa737 + 4f91678 commit 5349926

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ bool deleteFromExisting
266266
void DeleteCompetencyAssessmentQuestion(int frameworkCompetencyId, int assessmentQuestionId, int adminId);
267267

268268
void DeleteCompetencyLearningResource(int competencyLearningResourceId, int adminId);
269+
void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId);
269270
}
270271

271272
public class FrameworkDataService : IFrameworkDataService
@@ -2460,5 +2461,22 @@ public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
24602461
new { frameworkId, competencyGroupId }
24612462
).Single();
24622463
}
2464+
2465+
public void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId)
2466+
{
2467+
var numberOfAffectedRows = connection.Execute(
2468+
@"UPDATE FrameworkCompetencies
2469+
SET FrameworkCompetencyGroupId = @frameworkCompetencyGroupId, UpdatedByAdminID = @adminId
2470+
WHERE ID = @competencyGroupId AND FrameworkCompetencyGroupId <> @frameworkCompetencyGroupId",
2471+
new { frameworkCompetencyGroupId, competencyGroupId, adminId }
2472+
);
2473+
if (numberOfAffectedRows < 1)
2474+
{
2475+
logger.LogWarning(
2476+
"Not updating framework competencies framework competency group id as db update failed. " +
2477+
$"frameworkCompetencyGroupId: {frameworkCompetencyGroupId}, competencyGroupId: {competencyGroupId}."
2478+
);
2479+
}
2480+
}
24632481
}
24642482
}

DigitalLearningSolutions.Web/Services/FrameworkService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ bool deleteFromExisting
261261
void DeleteCompetencyAssessmentQuestion(int frameworkCompetencyId, int assessmentQuestionId, int adminId);
262262

263263
void DeleteCompetencyLearningResource(int competencyLearningResourceId, int adminId);
264+
void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId);
264265
}
265266
public class FrameworkService : IFrameworkService
266267
{
@@ -729,5 +730,10 @@ public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
729730
{
730731
return frameworkDataService.GetFrameworkCompetencyGroupId(frameworkId, competencyGroupId);
731732
}
733+
734+
public void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId)
735+
{
736+
frameworkDataService.UpdateFrameworkCompetencyFrameworkCompetencyGroup(competencyGroupId, frameworkCompetencyGroupId, adminId);
737+
}
732738
}
733739
}

DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook
3636
var competencyRows = table.Rows().Skip(1).Select(row => new CompetencyTableRow(table, row)).ToList();
3737
var newCompetencyIds = competencyRows.Select(row => row.ID ?? 0).ToList();
3838
var existingIds = frameworkService.GetFrameworkCompetencyOrder(frameworkId, newCompetencyIds);
39+
var existingGroups = frameworkService
40+
.GetFrameworkCompetencyGroups(frameworkId)
41+
.Select(row => row.Name)
42+
.Distinct()
43+
.ToList();
44+
var newGroups = competencyRows.Select(row => row.CompetencyGroup ?? "").ToList();
3945
foreach (var competencyRow in competencyRows)
4046
{
41-
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds);
47+
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds, existingGroups, newGroups);
4248
}
4349
return new ImportCompetenciesResult(competencyRows);
4450
}
45-
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds)
51+
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds, List<string> existingGroups, List<string> newGroups)
4652
{
53+
4754
if (competencyRow.ID == null)
4855
{
4956
competencyRow.RowStatus = RowStatus.CompetencyInserted;
@@ -64,6 +71,16 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int>
6471
{
6572
competencyRow.Reordered = true;
6673
}
74+
else
75+
{
76+
var groupName = (string)(competencyRow?.CompetencyGroup);
77+
originalIndex = existingGroups.IndexOf(groupName);
78+
newIndex = newGroups.IndexOf(groupName);
79+
if (originalIndex != newIndex)
80+
{
81+
competencyRow.Reordered = true;
82+
}
83+
}
6784
}
6885
}
6986
competencyRow.Validate();
@@ -124,10 +141,10 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
124141
if (reorderCompetenciesOption == 2)
125142
{
126143
var distinctCompetencyGroups = competenciesRows
127-
.Where(row => !string.IsNullOrWhiteSpace(row.CompetencyGroup))
128-
.Select(row => row.CompetencyGroup)
129-
.Distinct()
130-
.ToList();
144+
.Where(row => !string.IsNullOrWhiteSpace(row.CompetencyGroup))
145+
.Select(row => row.CompetencyGroup)
146+
.Distinct()
147+
.ToList();
131148
for (int i = 0; i < competencyGroupCount; i++)
132149
{
133150
var existingGroups = frameworkService.GetFrameworkCompetencyGroups(frameworkId).Select(row => new { row.ID, row.Name })
@@ -177,6 +194,7 @@ CompetencyTableRow competencyRow
177194
if (newCompetencyGroupId > 0)
178195
{
179196
frameworkCompetencyGroupId = frameworkService.InsertFrameworkCompetencyGroup(newCompetencyGroupId, frameworkId, adminId);
197+
frameworkService.UpdateFrameworkCompetencyFrameworkCompetencyGroup(competencyRow.ID, (int)frameworkCompetencyGroupId, adminId);
180198
if (frameworkCompetencyGroupId > maxFrameworkCompetencyGroupId)
181199
{
182200
maxFrameworkCompetencyGroupId = (int)frameworkCompetencyGroupId;
@@ -185,6 +203,7 @@ CompetencyTableRow competencyRow
185203
else
186204
{
187205
frameworkCompetencyGroupId = frameworkService.GetFrameworkCompetencyGroupId(frameworkId, newCompetencyGroupId);
206+
188207
var isUpdated = frameworkService.UpdateFrameworkCompetencyGroup((int)frameworkCompetencyGroupId, newCompetencyGroupId, competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminId);
189208
competencyRow.RowStatus = RowStatus.CompetencyGroupUpdated;
190209
}

0 commit comments

Comments
 (0)