Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ bool deleteFromExisting
void DeleteCompetencyAssessmentQuestion(int frameworkCompetencyId, int assessmentQuestionId, int adminId);

void DeleteCompetencyLearningResource(int competencyLearningResourceId, int adminId);
void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId);
}

public class FrameworkDataService : IFrameworkDataService
Expand Down Expand Up @@ -2460,5 +2461,22 @@ public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
new { frameworkId, competencyGroupId }
).Single();
}

public void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId)
{
var numberOfAffectedRows = connection.Execute(
@"UPDATE FrameworkCompetencies
SET FrameworkCompetencyGroupId = @frameworkCompetencyGroupId, UpdatedByAdminID = @adminId
WHERE ID = @competencyGroupId AND FrameworkCompetencyGroupId <> @frameworkCompetencyGroupId",
new { frameworkCompetencyGroupId, competencyGroupId, adminId }
);
if (numberOfAffectedRows < 1)
{
logger.LogWarning(
"Not updating framework competencies framework competency group id as db update failed. " +
$"frameworkCompetencyGroupId: {frameworkCompetencyGroupId}, competencyGroupId: {competencyGroupId}."
);
}
}
}
}
6 changes: 6 additions & 0 deletions DigitalLearningSolutions.Web/Services/FrameworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ bool deleteFromExisting
void DeleteCompetencyAssessmentQuestion(int frameworkCompetencyId, int assessmentQuestionId, int adminId);

void DeleteCompetencyLearningResource(int competencyLearningResourceId, int adminId);
void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId);
}
public class FrameworkService : IFrameworkService
{
Expand Down Expand Up @@ -729,5 +730,10 @@ public int GetFrameworkCompetencyGroupId(int frameworkId, int competencyGroupId)
{
return frameworkDataService.GetFrameworkCompetencyGroupId(frameworkId, competencyGroupId);
}

public void UpdateFrameworkCompetencyFrameworkCompetencyGroup(int? competencyGroupId, int frameworkCompetencyGroupId, int adminId)
{
frameworkDataService.UpdateFrameworkCompetencyFrameworkCompetencyGroup(competencyGroupId, frameworkCompetencyGroupId, adminId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ public ImportCompetenciesResult PreProcessCompetenciesTable(IXLWorkbook workbook
var competencyRows = table.Rows().Skip(1).Select(row => new CompetencyTableRow(table, row)).ToList();
var newCompetencyIds = competencyRows.Select(row => row.ID ?? 0).ToList();
var existingIds = frameworkService.GetFrameworkCompetencyOrder(frameworkId, newCompetencyIds);
var existingGroups = frameworkService
.GetFrameworkCompetencyGroups(frameworkId)
.Select(row => row.Name)
.Distinct()
.ToList();
var newGroups = competencyRows.Select(row => row.CompetencyGroup ?? "").ToList();
foreach (var competencyRow in competencyRows)
{
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds);
PreProcessCompetencyRow(competencyRow, newCompetencyIds, existingIds, existingGroups, newGroups);
}
return new ImportCompetenciesResult(competencyRows);
}
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds)
private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int> newIds, List<int> existingIds, List<string> existingGroups, List<string> newGroups)
{

if (competencyRow.ID == null)
{
competencyRow.RowStatus = RowStatus.CompetencyInserted;
Expand All @@ -64,6 +71,16 @@ private void PreProcessCompetencyRow(CompetencyTableRow competencyRow, List<int>
{
competencyRow.Reordered = true;
}
else
{
var groupName = (string)(competencyRow?.CompetencyGroup);
originalIndex = existingGroups.IndexOf(groupName);
newIndex = newGroups.IndexOf(groupName);
if (originalIndex != newIndex)
{
competencyRow.Reordered = true;
}
}
}
}
competencyRow.Validate();
Expand Down Expand Up @@ -124,10 +141,10 @@ internal ImportCompetenciesResult ProcessCompetenciesTable(IXLTable table, int a
if (reorderCompetenciesOption == 2)
{
var distinctCompetencyGroups = competenciesRows
.Where(row => !string.IsNullOrWhiteSpace(row.CompetencyGroup))
.Select(row => row.CompetencyGroup)
.Distinct()
.ToList();
.Where(row => !string.IsNullOrWhiteSpace(row.CompetencyGroup))
.Select(row => row.CompetencyGroup)
.Distinct()
.ToList();
for (int i = 0; i < competencyGroupCount; i++)
{
var existingGroups = frameworkService.GetFrameworkCompetencyGroups(frameworkId).Select(row => new { row.ID, row.Name })
Expand Down Expand Up @@ -177,6 +194,7 @@ CompetencyTableRow competencyRow
if (newCompetencyGroupId > 0)
{
frameworkCompetencyGroupId = frameworkService.InsertFrameworkCompetencyGroup(newCompetencyGroupId, frameworkId, adminId);
frameworkService.UpdateFrameworkCompetencyFrameworkCompetencyGroup(competencyRow.ID, (int)frameworkCompetencyGroupId, adminId);
if (frameworkCompetencyGroupId > maxFrameworkCompetencyGroupId)
{
maxFrameworkCompetencyGroupId = (int)frameworkCompetencyGroupId;
Expand All @@ -185,6 +203,7 @@ CompetencyTableRow competencyRow
else
{
frameworkCompetencyGroupId = frameworkService.GetFrameworkCompetencyGroupId(frameworkId, newCompetencyGroupId);

var isUpdated = frameworkService.UpdateFrameworkCompetencyGroup((int)frameworkCompetencyGroupId, newCompetencyGroupId, competencyRow.CompetencyGroup, competencyRow.GroupDescription, adminId);
competencyRow.RowStatus = RowStatus.CompetencyGroupUpdated;
}
Expand Down
Loading