diff --git a/DigitalLearningSolutions.Data.Migrations/202504241045_Alter_ReorderFrameworkCompetency.cs b/DigitalLearningSolutions.Data.Migrations/202504241045_Alter_ReorderFrameworkCompetency.cs
new file mode 100644
index 0000000000..f4530aa7f9
--- /dev/null
+++ b/DigitalLearningSolutions.Data.Migrations/202504241045_Alter_ReorderFrameworkCompetency.cs
@@ -0,0 +1,19 @@
+
+
+namespace DigitalLearningSolutions.Data.Migrations
+{
+ using FluentMigrator;
+
+ [Migration(202504241045)]
+ 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);
+ }
+ }
+}
diff --git a/DigitalLearningSolutions.Data.Migrations/202504241115_UpdateFrameworkCompetenciesOrdering.cs b/DigitalLearningSolutions.Data.Migrations/202504241115_UpdateFrameworkCompetenciesOrdering.cs
new file mode 100644
index 0000000000..aec171d621
--- /dev/null
+++ b/DigitalLearningSolutions.Data.Migrations/202504241115_UpdateFrameworkCompetenciesOrdering.cs
@@ -0,0 +1,21 @@
+namespace DigitalLearningSolutions.Data.Migrations
+{
+ using FluentMigrator;
+ [Migration(202504241115)]
+ 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;");
+ }
+ }
+}
diff --git a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs
index 1b4edf4c6f..d49dcbba16 100644
--- a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs
+++ b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs
@@ -2436,6 +2436,50 @@ internal static string TD_5412_Alter_SendExpiredTBCReminders_Up {
}
}
+ ///
+ /// Looks up a localized string similar to /****** Object: StoredProcedure [dbo].[ReorderFrameworkCompetency] Script Date: 24/04/2025 09:23:17 ******/
+ ///SET ANSI_NULLS ON
+ ///GO
+ ///
+ ///SET QUOTED_IDENTIFIER ON
+ ///GO
+ ///
+ ///-- =============================================
+ ///-- Author: Kevin Whittaker
+ ///-- Create date: 04/01/2021
+ ///-- Description: Reorders the FrameworkCompetencies in a given FrameworkCompetencyGroup - moving the given competency up or down.
+ ///-- =============================================
+ ///ALTER PROCEDURE [dbo].[ReorderFrameworkCompetency]
+ /// [rest of string was truncated]";.
+ ///
+ internal static string TD_5447_Alter_ReorderFrameworkCompetency_Down {
+ get {
+ return ResourceManager.GetString("TD_5447_Alter_ReorderFrameworkCompetency_Down", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to /****** Object: StoredProcedure [dbo].[ReorderFrameworkCompetency] Script Date: 24/04/2025 09:23:17 ******/
+ ///SET ANSI_NULLS ON
+ ///GO
+ ///
+ ///SET QUOTED_IDENTIFIER ON
+ ///GO
+ ///
+ ///-- =============================================
+ ///-- Author: Kevin Whittaker
+ ///-- Create date: 04/01/2021
+ ///-- Description: Reorders the FrameworkCompetencies in a given FrameworkCompetencyGroup - moving the given competency up or down.
+ ///-- =============================================
+ ///ALTER PROCEDURE [dbo].[ReorderFrameworkCompetency]
+ /// [rest of string was truncated]";.
+ ///
+ internal static string TD_5447_Alter_ReorderFrameworkCompetency_Up {
+ get {
+ return ResourceManager.GetString("TD_5447_Alter_ReorderFrameworkCompetency_Up", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to /****** Object: StoredProcedure [dbo].[GetActiveAvailableCustomisationsForCentreFiltered_V6] Script Date: 29/09/2022 19:11:04 ******/
///SET ANSI_NULLS ON
diff --git a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx
index a951c296c9..00db99e650 100644
--- a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx
+++ b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx
@@ -475,4 +475,10 @@
..\Scripts\TD-5412-Alter_SendExpiredTBCReminders_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16
+
+ ..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16
+
+
+ ..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16
+
\ No newline at end of file
diff --git a/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Down.sql b/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Down.sql
new file mode 100644
index 0000000000..56bac72b67
Binary files /dev/null and b/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Down.sql differ
diff --git a/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Up.sql b/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Up.sql
new file mode 100644
index 0000000000..cc17b68152
Binary files /dev/null and b/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Up.sql differ
diff --git a/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs b/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs
index 3bdf62f412..912902f704 100644
--- a/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs
+++ b/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs
@@ -680,9 +680,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)
@@ -707,7 +709,7 @@ FROM [FrameworkCompetencies]
new { competencyId, frameworkCompetencyGroupID }
);
}
- if(addDefaultQuestions)
+ if (addDefaultQuestions)
{
AddDefaultQuestionsToCompetency(competencyId, frameworkId);
}