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
Expand Up @@ -12,11 +12,11 @@ public override void Up()
.WithColumn("SelfAssessmentId").AsInt32().NotNullable().ForeignKey("SelfAssessments", "ID")
.WithColumn("FrameworkId").AsInt32().NotNullable().ForeignKey("Frameworks", "ID")
.WithColumn("CreatedDate").AsDateTime().NotNullable().WithDefault(SystemMethods.CurrentDateTime)
.WithColumn("CreatedByUserId").AsInt32().NotNullable().ForeignKey("Users", "ID")
.WithColumn("CreatedByAdminId").AsInt32().NotNullable().ForeignKey("AdminAccounts", "ID")
.WithColumn("RemovedDate").AsDateTime().Nullable()
.WithColumn("RemovedByUserId").AsInt32().Nullable().ForeignKey("Users", "ID")
.WithColumn("RemovedByAdminId").AsInt32().Nullable().ForeignKey("AdminAccounts", "ID")
.WithColumn("AmendedDate").AsDateTime().Nullable()
.WithColumn("AmendedByUserId").AsInt32().Nullable().ForeignKey("Users", "ID");
.WithColumn("AmendedByAdminId").AsInt32().Nullable().ForeignKey("AdminAccounts", "ID");
Create.Table("SelfAssessmentTaskStatus")
.WithColumn("ID").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("SelfAssessmentId").AsInt32().NotNullable().ForeignKey("SelfAssessments", "ID").Unique()
Expand All @@ -32,13 +32,13 @@ public override void Up()
.WithColumn("SupervisorRolesTaskStatus").AsBoolean().Nullable()
.WithColumn("SelfAssessmentOptionsTaskStatus").AsBoolean().Nullable()
.WithColumn("ReviewTaskStatus").AsBoolean().Nullable();
Execute.Sql($@"INSERT INTO SelfAssessmentFrameworks (SelfAssessmentId, FrameworkId, CreatedByUserId)
SELECT sa.ID, fc.FrameworkID, aa.UserID
Alter.Table("SelfAssessments").AlterColumn("Description").AsString(int.MaxValue).Nullable();
Execute.Sql($@"INSERT INTO SelfAssessmentFrameworks (SelfAssessmentId, FrameworkId, CreatedByAdminId)
SELECT sa.ID, fc.FrameworkID, sa.CreatedByAdminID
FROM SelfAssessments AS sa INNER JOIN
SelfAssessmentStructure AS sas ON sa.ID = sas.SelfAssessmentID INNER JOIN
FrameworkCompetencies AS fc ON sas.CompetencyID = fc.CompetencyID INNER JOIN
AdminAccounts AS aa ON sa.CreatedByAdminID = aa.ID
GROUP BY sa.ID, fc.FrameworkID, aa.UserID
FrameworkCompetencies AS fc ON sas.CompetencyID = fc.CompetencyID
GROUP BY sa.ID, fc.FrameworkID, sa.CreatedByAdminID
");
Execute.Sql($@"INSERT INTO SelfAssessmentTaskStatus (SelfAssessmentId, IntroductoryTextTaskStatus, BrandingTaskStatus, VocabularyTaskStatus, WorkingGroupTaskStatus, NationalRoleProfileTaskStatus, FrameworkLinksTaskStatus, SelectCompetenciesTaskStatus, OptionalCompetenciesTaskStatus, RoleRequirementsTaskStatus, SupervisorRolesTaskStatus, SelfAssessmentOptionsTaskStatus)
SELECT ID, 1,1,1,1,1,1,1,1,1,1,1
Expand All @@ -50,6 +50,7 @@ public override void Down()
{
Delete.Table("SelfAssessmentFrameworks");
Delete.Table("SelfAssessmentTaskStatus");
Alter.Table("SelfAssessments").AlterColumn("Description").AsString(int.MaxValue).NotNullable();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
namespace DigitalLearningSolutions.Data.DataServices
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Dapper;
using DigitalLearningSolutions.Data.Models.Common;
using DigitalLearningSolutions.Data.Models.CompetencyAssessments;
using DigitalLearningSolutions.Data.Models.Frameworks;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.Extensions.Logging;

public interface ICompetencyAssessmentDataService
Expand All @@ -24,8 +28,16 @@ public interface ICompetencyAssessmentDataService
bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName);

bool UpdateCompetencyAssessmentProfessionalGroup(int competencyAssessmentId, int adminId, int? nrpProfessionalGroupID);
bool UpdateCompetencyAssessmentBranding(
int competencyAssessmentId,
int brandId,
int categoryId,
int adminId
);
bool UpdateCompetencyAssessmentDescription(int competencyAssessmentId, int adminId, string competencyAssessmentDescription);
//INSERT DATA

int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName);
bool InsertSelfAssessmentFramework(int adminId, int selfAssessmentId, int frameworkId);
//DELETE DATA
}

Expand Down Expand Up @@ -121,6 +133,33 @@ FROM SelfAssessmentCollaborators
).FirstOrDefault();
}

public int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName)
{
if ((competencyAssessmentName.Length == 0) | (adminId < 1))
{
logger.LogWarning(
$"Not inserting competency assessmente as it failed server side validation. AdminId: {adminId}, competencyAssessmentName: {competencyAssessmentName}"
);
return -1;
}
var result = connection.ExecuteScalar(
@"SELECT COUNT(*) FROM SelfAssessments WHERE [Name] = @competencyAssessmentName",
new { competencyAssessmentName }
);
int existingSelfAssessments = Convert.ToInt32(result);
if (existingSelfAssessments > 0)
{
return -1;
}
var assessmentId = connection.QuerySingle<int>(
@"INSERT INTO SelfAssessments ([Name], CreatedByCentreID, CreatedByAdminID)
OUTPUT INSERTED.Id
VALUES (@competencyAssessmentName, @centreId, @adminId)"
,
new { competencyAssessmentName, centreId, adminId }
);
return assessmentId;
}
public bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName)
{
if ((competencyAssessmentName.Length == 0) | (adminId < 1) | (competencyAssessmentId < 1))
Expand All @@ -130,11 +169,11 @@ public bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int admin
);
return false;
}

var existingSelfAssessments = (int)connection.ExecuteScalar(
var result = connection.ExecuteScalar(
@"SELECT COUNT(*) FROM SelfAssessments WHERE [Name] = @competencyAssessmentName AND ID <> @competencyAssessmentId",
new { competencyAssessmentName, competencyAssessmentId }
);
int existingSelfAssessments = Convert.ToInt32(result);
if (existingSelfAssessments > 0)
{
return false;
Expand Down Expand Up @@ -179,10 +218,11 @@ ORDER BY ProfessionalGroup"

public bool UpdateCompetencyAssessmentProfessionalGroup(int competencyAssessmentId, int adminId, int? nrpProfessionalGroupID)
{
var sameCount = (int)connection.ExecuteScalar(
var result = connection.ExecuteScalar(
@"SELECT COUNT(*) FROM CompetencyAssessments WHERE ID = @competencyAssessmentId AND NRPProfessionalGroupID = @nrpProfessionalGroupID",
new { competencyAssessmentId, nrpProfessionalGroupID }
);
int sameCount = Convert.ToInt32(result);
if (sameCount > 0)
{
//same so don't update:
Expand All @@ -202,5 +242,75 @@ public bool UpdateCompetencyAssessmentProfessionalGroup(int competencyAssessment

return false;
}
public bool UpdateCompetencyAssessmentBranding(
int competencyAssessmentId,
int brandId,
int categoryId,
int adminId
)
{
if ((competencyAssessmentId < 1) | (brandId < 1) | (categoryId < 1) | (adminId < 1))
{
logger.LogWarning(
$"Not updating competency assessment as it failed server side validation. competencyAssessmentId: {competencyAssessmentId}, brandId: {brandId}, categoryId: {categoryId}, AdminId: {adminId}"
);
return false;
}

var numberOfAffectedRows = connection.Execute(
@"UPDATE SelfAssessments SET BrandID = @brandId, CategoryID = @categoryId, UpdatedByAdminID = @adminId
WHERE ID = @competencyAssessmentId",
new { brandId, categoryId, adminId, competencyAssessmentId }
);
if (numberOfAffectedRows < 1)
{
logger.LogWarning(
"Not updating competency assessment as db update failed. " +
$"frameworkId: {competencyAssessmentId}, brandId: {brandId}, categoryId: {categoryId}, AdminId: {adminId}"
);
return false;
}

return true;
}

public bool UpdateCompetencyAssessmentDescription(int competencyAssessmentId, int adminId, string competencyAssessmentDescription)
{
var numberOfAffectedRows = connection.Execute(
@"UPDATE SelfAssessments SET Description = @competencyAssessmentDescription, UpdatedByAdminID = @adminId
WHERE ID = @competencyAssessmentId",
new { adminId, competencyAssessmentId, competencyAssessmentDescription }
);
if (numberOfAffectedRows < 1)
{
logger.LogWarning(
"Not updating competency assessment as db update failed. " +
$"frameworkId: {competencyAssessmentId}, competencyAssessmentDescription: {competencyAssessmentDescription}, AdminId: {adminId}"
);
return false;
}
return true;
}

public bool InsertSelfAssessmentFramework(int adminId, int selfAssessmentId, int frameworkId)
{
var numberOfAffectedRows = connection.Execute(
@"INSERT INTO SelfAssessmentFrameworks (SelfAssessmentId, FrameworkId, CreatedByAdminId)
SELECT @selfAssessmentId, @frameworkId, @adminId
WHERE NOT EXISTS (SELECT 1 FROM SelfAssessmentFrameworks WHERE SelfAssessmentId = @selfAssessmentId AND FrameworkId = @frameworkId)"
,
new { adminId, selfAssessmentId, frameworkId }
);
if (numberOfAffectedRows < 1)
{
logger.LogWarning(
"Not inserting SelfAssessmentFrameworks record as db insert failed. " +
$"selfAssessmentId: {selfAssessmentId}, frameworkId: {frameworkId}, AdminId: {adminId}"
);
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public class FrameworkDataService : IFrameworkDataService
fwr.ID AS FrameworkReviewID";

private const string BrandedFrameworkFields =
@",(SELECT BrandName
@", FW.Description, (SELECT BrandName
FROM Brands
WHERE (BrandID = FW.BrandID)) AS Brand,
(SELECT CategoryName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class BrandedFramework : BaseFramework
{
public string? Description { get; set; }
public string? Brand
{
get => brand;
Expand Down
Loading
Loading