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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


namespace DigitalLearningSolutions.Data.Migrations
{
using FluentMigrator;

[Migration(202504281045)]
public class Alter_ReorderFrameworkCompetency : Migration
{
public override void Up()
{
Execute.Sql(Properties.Resources.TD_5447_Alter_ReorderFrameworkCompetency_Up);
}
public override void Down()
{
Execute.Sql(Properties.Resources.TD_5447_Alter_ReorderFrameworkCompetency_Down);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace DigitalLearningSolutions.Data.Migrations
{
using FluentMigrator;
[Migration(202504281115)]
public class UpdateFrameworkCompetenciesOrdering : ForwardOnlyMigration
{
public override void Up()
{
Execute.Sql(@"WITH Ranked AS (
    SELECT ID,
            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY SysStartTime) AS NewOrder
    FROM FrameworkCompetencies
Where FrameworkCompetencyGroupID is null
)
UPDATE fc
SET fc.Ordering = r.NewOrder
FROM FrameworkCompetencies fc
JOIN Ranked r ON fc.ID = r.ID;");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,10 @@
<data name="TD_5514_Alter_SendExpiredTBCReminders_Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Scripts\TD-5514-Alter_SendExpiredTBCReminders_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
</data>
<data name="TD_5447_Alter_ReorderFrameworkCompetency_Down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
</data>
<data name="TD_5447_Alter_ReorderFrameworkCompetency_Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
</data>
</root>
Binary file not shown.
Binary file not shown.
53 changes: 44 additions & 9 deletions DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ string direction
void RemoveCustomFlag(int flagId);
void RemoveCollaboratorFromFramework(int frameworkId, int id);

void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int adminId);
void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int frameworkId, int adminId);

void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId);
void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId);

void DeleteFrameworkDefaultQuestion(
int frameworkId,
Expand Down Expand Up @@ -689,9 +689,11 @@ public int InsertFrameworkCompetency(
var numberOfAffectedRows = connection.Execute(
@"INSERT INTO FrameworkCompetencies ([CompetencyID], FrameworkCompetencyGroupID, UpdatedByAdminID, Ordering, FrameworkID)
VALUES (@competencyId, @frameworkCompetencyGroupID, @adminId, COALESCE
((SELECT MAX(Ordering) AS OrderNum
FROM [FrameworkCompetencies]
WHERE ([FrameworkCompetencyGroupID] = @frameworkCompetencyGroupID)), 0)+1, @frameworkId)",
((SELECT MAX(Ordering) AS OrderNum
FROM [FrameworkCompetencies]
WHERE ((@frameworkCompetencyGroupID IS NULL AND FrameworkCompetencyGroupID IS NULL) OR
(@frameworkCompetencyGroupID IS NOT NULL AND FrameworkCompetencyGroupID = @frameworkCompetencyGroupID)) AND
FrameworkID = @frameworkId ), 0)+1, @frameworkId)",
new { competencyId, frameworkCompetencyGroupID, adminId, frameworkId }
);
if (numberOfAffectedRows < 1)
Expand Down Expand Up @@ -1143,7 +1145,7 @@ public void MoveFrameworkCompetency(int frameworkCompetencyId, bool singleStep,
);
}

public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int adminId)
public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int frameworkId, int adminId)
{
if ((frameworkCompetencyGroupId < 1) | (adminId < 1))
{
Expand Down Expand Up @@ -1174,7 +1176,23 @@ public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int c
new { frameworkCompetencyGroupId }
);

if (numberOfAffectedRows < 1)
if (numberOfAffectedRows > 0)
{
connection.Execute(
@"WITH Ranked AS (
    SELECT ID,
            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY Ordering) AS NewOrder
    FROM FrameworkCompetencyGroups
Where FrameworkID = @frameworkID
)
UPDATE fcg
SET fcg.Ordering = r.NewOrder
FROM FrameworkCompetencyGroups fcg
JOIN Ranked r ON fcg.ID = r.ID;",
new { frameworkId }
);
}
else
{
logger.LogWarning(
"Not deleting framework competency group as db update failed. " +
Expand Down Expand Up @@ -1219,7 +1237,7 @@ public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int c
}
}

public void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId)
public void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId)
{
var competencyId = connection.QuerySingle<int>(
@"SELECT CompetencyID FROM FrameworkCompetencies WHERE ID = @frameworkCompetencyId",
Expand All @@ -1243,7 +1261,24 @@ public void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId)
@"DELETE FROM FrameworkCompetencies WHERE ID = @frameworkCompetencyId",
new { frameworkCompetencyId }
);
if (numberOfAffectedRows < 1)
if (numberOfAffectedRows > 0)
{
connection.Execute(
@"WITH Ranked AS (
    SELECT ID,
            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY Ordering) AS NewOrder
    FROM FrameworkCompetencies
Where (FrameworkCompetencyGroupID = @frameworkCompetencyGroupID) OR (FrameworkCompetencyGroupID IS NULL AND @frameworkCompetencyGroupID IS NULL) AND
FrameworkID = @frameworkID
)
UPDATE fc
SET fc.Ordering = r.NewOrder
FROM FrameworkCompetencies fc
JOIN Ranked r ON fc.ID = r.ID;",
new { frameworkCompetencyGroupId, frameworkId }
);
}
else
{
logger.LogWarning(
"Not deleting framework competency as db update failed. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public IActionResult DeleteFrameworkCompetencyGroup(int frameworkId, int compete

var adminId = GetAdminId();

frameworkService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, adminId);
frameworkService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, frameworkId, adminId);

return new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId }));
}
Expand Down Expand Up @@ -235,7 +235,7 @@ public IActionResult DeleteFrameworkCompetency(int frameworkId, int frameworkCom
{
var userRole = frameworkService.GetAdminUserRoleForFrameworkId(GetAdminId(), frameworkId);
if (userRole < 2) return StatusCode(403);
frameworkService.DeleteFrameworkCompetency(frameworkCompetencyId, GetAdminId());
frameworkService.DeleteFrameworkCompetency(frameworkCompetencyId, frameworkCompetencyGroupId, frameworkId, GetAdminId());
return frameworkCompetencyGroupId != null ? new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId }) + "#fcgroup-" + frameworkCompetencyGroupId.ToString()) : new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId }) + "#fc-ungrouped");
}
[Route("/Frameworks/{frameworkId}/Competency/{frameworkCompetencyGroupId:int=0}/{frameworkCompetencyId}/Preview/")]
Expand Down
12 changes: 6 additions & 6 deletions DigitalLearningSolutions.Web/Services/FrameworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ string direction
void RemoveCustomFlag(int flagId);
void RemoveCollaboratorFromFramework(int frameworkId, int id);

void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int adminId);
void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int frameworkId, int adminId);

void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId);
void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId);

void DeleteFrameworkDefaultQuestion(
int frameworkId,
Expand Down Expand Up @@ -316,14 +316,14 @@ public void DeleteCompetencyLearningResource(int competencyLearningResourceId, i
frameworkDataService.DeleteCompetencyLearningResource(competencyLearningResourceId, adminId);
}

public void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId)
public void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId)
{
frameworkDataService.DeleteFrameworkCompetency(frameworkCompetencyId, adminId);
frameworkDataService.DeleteFrameworkCompetency(frameworkCompetencyId, frameworkCompetencyGroupId, frameworkId, adminId);
}

public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int adminId)
public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int frameworkId, int adminId)
{
frameworkDataService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, adminId);
frameworkDataService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, frameworkId, adminId);
}

public void DeleteFrameworkDefaultQuestion(int frameworkId, int assessmentQuestionId, int adminId, bool deleteFromExisting)
Expand Down
Loading