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 @@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;

public interface ICompetencyAssessmentDataService
{
//GET DATA
Expand All @@ -34,6 +33,8 @@ public interface ICompetencyAssessmentDataService
IEnumerable<Competency> GetCompetenciesForCompetencyAssessment(int competencyAssessmentId);
IEnumerable<LinkedFramework> GetLinkedFrameworksForCompetencyAssessment(int competencyAssessmentId);
int[] GetLinkedFrameworkCompetencyIds(int competencyAssessmentId, int frameworkId);
CompetencyAssessmentFeatures? GetCompetencyAssessmentFeaturesTaskStatus(int competencyAssessmentId);
int? GetSelfAssessmentStructure(int competencyAssessmentId);

//UPDATE DATA
bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName);
Expand Down Expand Up @@ -64,12 +65,15 @@ void MoveCompetencyGroupInSelfAssessment(int competencyAssessmentId,
int groupId,
string direction
);
public bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus,
bool workingGroupStatus, bool AllframeworkCompetenciesStatus);
void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId);

//INSERT DATA
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName);
bool InsertSelfAssessmentFramework(int adminId, int selfAssessmentId, int frameworkId);
bool InsertCompetenciesIntoAssessmentFromFramework(int[] selectedCompetencyIds, int frameworkId, int competencyAssessmentId);

bool InsertSelfAssessmentStructure(int selfAssessmentId, int? frameworkId);
//DELETE DATA
bool RemoveFrameworkCompetenciesFromAssessment(int competencyAssessmentId, int frameworkId);
bool RemoveCompetencyFromAssessment(int competencyAssessmentId, int competencyId);
Expand Down Expand Up @@ -754,5 +758,112 @@ public void MoveCompetencyGroupInSelfAssessment(int competencyAssessmentId, int
commandType: CommandType.StoredProcedure
);
}

public bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus,
bool workingGroupStatus, bool AllframeworkCompetenciesStatus)
{
var numberOfAffectedRows = connection.Execute(
@"IF EXISTS (SELECT 1 FROM SelfAssessmentTaskStatus WHERE SelfAssessmentId = @id)
BEGIN
UPDATE SelfAssessmentTaskStatus
SET IntroductoryTextTaskStatus = CASE WHEN @descriptionStatus = 1 THEN 1 ELSE NULL END,
BrandingTaskStatus = CASE WHEN @providerandCategoryStatus = 1 THEN 1 ELSE NULL END,
VocabularyTaskStatus = CASE WHEN @vocabularyStatus = 1 THEN 1 ELSE NULL END,
WorkingGroupTaskStatus = CASE WHEN @workingGroupStatus = 1 THEN 1 ELSE NULL END,
FrameworkLinksTaskStatus = CASE WHEN @AllframeworkCompetenciesStatus = 1 THEN 1 ELSE NULL END
WHERE SelfAssessmentId = @id;
END
ELSE
BEGIN
INSERT INTO SelfAssessmentTaskStatus
(SelfAssessmentId, IntroductoryTextTaskStatus, BrandingTaskStatus, VocabularyTaskStatus, WorkingGroupTaskStatus, FrameworkLinksTaskStatus)
VALUES
(
@id,
CASE WHEN @descriptionStatus = 1 THEN 1 ELSE NULL END,
CASE WHEN @providerandCategoryStatus = 1 THEN 1 ELSE NULL END,
CASE WHEN @vocabularyStatus = 1 THEN 1 ELSE NULL END,
CASE WHEN @workingGroupStatus = 1 THEN 1 ELSE NULL END,
CASE WHEN @AllframeworkCompetenciesStatus = 1 THEN 1 ELSE NULL END
);
END",
new { id, descriptionStatus, providerandCategoryStatus, vocabularyStatus, workingGroupStatus, AllframeworkCompetenciesStatus }
);
if (numberOfAffectedRows < 1)
{
logger.LogWarning(
"Not updating SelfAssessmentTaskStatus as db update failed. " +
$"SelfAssessmentId: {id}, IntroductoryTextTaskStatus: {descriptionStatus}, BrandingTaskStatus: {providerandCategoryStatus}, " +
$"VocabularyTaskStatus: {vocabularyStatus}, WorkingGroupTaskStatus: {workingGroupStatus}, FrameworkLinksTaskStatus: {AllframeworkCompetenciesStatus}"
);
return false;
}
return true;
}

public CompetencyAssessmentFeatures? GetCompetencyAssessmentFeaturesTaskStatus(int competencyAssessmentId)
{
return connection.QueryFirstOrDefault<CompetencyAssessmentFeatures>(
@"SELECT s.ID, s.Name AS CompetencyAssessmentName, sts.IntroductoryTextTaskStatus AS DescriptionStatus, sts.BrandingTaskStatus AS ProviderandCategoryStatus,
sts.VocabularyTaskStatus AS VocabularyStatus, sts.WorkingGroupTaskStatus AS WorkingGroupStatus, sts.FrameworkLinksTaskStatus AS AllframeworkCompetenciesStatus
FROM SelfAssessments s INNER JOIN
SelfAssessmentTaskStatus sts ON s.ID = sts.SelfAssessmentId
WHERE s.ID = @competencyAssessmentId",
new { competencyAssessmentId }
);

}

public void UpdateSelfAssessmentFromFramework( int selfAssessmentId, int? frameworkId)
{

var numberOfAffectedRows = connection.Execute(
@"UPDATE s
SET
[Description] = COALESCE(F.[Description], 'No description provided'),
BrandID = F.BrandID,
CategoryID = F.CategoryID,
CreatedByCentreID = AU.CentreID,
CreatedByAdminID = F.OwnerAdminID
FROM SelfAssessments s
INNER JOIN Frameworks F ON F.ID = @frameworkId
INNER JOIN AdminUsers AU ON F.OwnerAdminID = AU.AdminID
WHERE s.id = @selfAssessmentId;"
,
new {selfAssessmentId, frameworkId }
);
}
public bool InsertSelfAssessmentStructure(int selfAssessmentId, int? frameworkId)
{

var numberOfAffectedRows = connection.Execute(
@"INSERT INTO SelfAssessmentStructure (SelfAssessmentID, CompetencyID, Ordering, CompetencyGroupID)
SELECT s.ID, FC.CompetencyID, ROW_NUMBER() OVER( ORDER BY FCG.Ordering, FC.Ordering ), FCG.CompetencyGroupID
FROM FrameworkCompetencies AS FC
INNER JOIN FrameworkCompetencyGroups AS FCG ON FC.FrameworkCompetencyGroupID = FCG.ID INNER JOIN
SelfAssessments s ON s.id = @selfAssessmentId
WHERE FC.FrameworkID = @frameworkId"
,
new { selfAssessmentId, frameworkId }
);
if (numberOfAffectedRows < 1)
{
logger.LogWarning(
"Not inserting SelfAssessmentStructure record as db insert failed. " +
$"selfAssessmentId: {selfAssessmentId}, frameworkId: {frameworkId}"
);
return false;
}

return true;
}
public int? GetSelfAssessmentStructure(int competencyAssessmentId)
{
return connection.QueryFirstOrDefault<int>(
@"SELECT 1 from dbo.SelfAssessmentStructure where selfassessmentid = @competencyAssessmentId",
new { competencyAssessmentId }
);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DigitalLearningSolutions.Data.Models.CompetencyAssessments
{
public class CompetencyAssessmentFeatures
{
public int ID { get; set; }
public string CompetencyAssessmentName { get; set; } = string.Empty;
public int UserRole { get; set; }
public bool DescriptionStatus { get; set; }
public bool ProviderandCategoryStatus { get; set; }
public bool VocabularyStatus { get; set; }
public bool WorkingGroupStatus { get; set; }
public bool AllframeworkCompetenciesStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.Models.Enums;
using DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments;
using GDS.MultiPageFormData.Enums;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -82,7 +83,6 @@ public IActionResult ViewCompetencyAssessments(string tabname, string? searchStr
isWorkforceManager
);
}

var currentTab = tabname == "All" ? CompetencyAssessmentsTab.AllCompetencyAssessments : CompetencyAssessmentsTab.MyCompetencyAssessments;
CompetencyAssessmentsViewModel? model = new CompetencyAssessmentsViewModel(
isWorkforceManager,
Expand All @@ -96,12 +96,18 @@ public IActionResult ViewCompetencyAssessments(string tabname, string? searchStr

[Route("/CompetencyAssessments/{actionName}/Name/{competencyAssessmentId}")]
[Route("/CompetencyAssessments/Framework/{frameworkId}/{actionName}/Name")]
[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/{actionName}/Name")]
[Route("/CompetencyAssessments/{actionName}/Name")]
[SetSelectedTab(nameof(NavMenuTab.CompetencyAssessments))]
public IActionResult CompetencyAssessmentName(string actionName, int competencyAssessmentId = 0, int? frameworkId = null)
{
var adminId = GetAdminID();
var competencyAssessmentBase = new CompetencyAssessmentBase();
if ((frameworkId.HasValue && frameworkId.Value != 0 && actionName == "New"))
{
var data = new CompetencyAssessmentFeaturesViewModel();
SetcompetencyAssessmentFeaturesData(data);
}
if (competencyAssessmentId > 0)
{
competencyAssessmentBase = competencyAssessmentService.GetCompetencyAssessmentBaseById(competencyAssessmentId, adminId);
Expand Down Expand Up @@ -129,6 +135,7 @@ public IActionResult CompetencyAssessmentName(string actionName, int competencyA
[HttpPost]
[Route("/CompetencyAssessments/{actionName}/Name/{competencyAssessmentId}")]
[Route("/CompetencyAssessments/Framework/{frameworkId}/{actionName}/Name")]
[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/{actionName}/Name")]
[Route("/CompetencyAssessments/{actionName}/Name")]
[SetSelectedTab(nameof(NavMenuTab.CompetencyAssessments))]
public IActionResult SaveProfileName(CompetencyAssessmentBase competencyAssessmentBase, string actionName, int competencyAssessmentId = 0, int? frameworkId = null)
Expand All @@ -153,6 +160,7 @@ public IActionResult SaveProfileName(CompetencyAssessmentBase competencyAssessme
return View("Name", competencyAssessmentBase);
}
competencyAssessmentId = competencyAssessmentService.InsertCompetencyAssessment(adminId, userCentreId, competencyAssessmentBase.CompetencyAssessmentName, frameworkId);
if(frameworkId.HasValue && frameworkId.Value != 0) return RedirectToAction("CompetencyAssessmentFeatures", new { competencyAssessmentId, frameworkId });
}
else
{
Expand All @@ -163,6 +171,9 @@ public IActionResult SaveProfileName(CompetencyAssessmentBase competencyAssessme
ModelState.AddModelError(nameof(CompetencyAssessmentBase.CompetencyAssessmentName), "Another competency assessment exists with that name. Please choose a different name.");
return View("Name", competencyAssessmentBase);
}
if (frameworkId.HasValue && frameworkId.Value != 0
&& competencyAssessmentId != 0
&& actionName == "Edit") return RedirectToAction("CompetencyAssessmentFeatures", new { competencyAssessmentId, frameworkId });
}
return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId, frameworkId });
}
Expand Down Expand Up @@ -640,5 +651,80 @@ public IActionResult ViewSelectedCompetencies(ViewSelectedCompetenciesFormData m
competencyAssessmentService.UpdateSelectCompetenciesTaskStatus(model.ID, model.TaskStatus.Value, null);
return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId = model.ID });
}

[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/Features")]
public IActionResult CompetencyAssessmentFeatures(int competencyAssessmentId, int? frameworkId = null)
{

var adminId = GetAdminID();
var data = GetcompetencyAssessmentFeaturesData();
if (!string.IsNullOrEmpty(data.CompetencyAssessmentName)) return View(data);
var competencyAssessmentBase = competencyAssessmentService.GetCompetencyAssessmentBaseById(competencyAssessmentId, adminId);
if (competencyAssessmentBase == null) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 500 });
if (competencyAssessmentBase.UserRole < 2) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
var baseModel = new CompetencyAssessmentFeaturesViewModel(competencyAssessmentBase.ID,
competencyAssessmentBase.CompetencyAssessmentName,
competencyAssessmentBase.UserRole,
frameworkId);
return View(baseModel);
}
[HttpPost]
[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/Features")]
public IActionResult CompetencyAssessmentFeatures(CompetencyAssessmentFeaturesViewModel featuresViewModel)
{
if (featuresViewModel == null) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 500 });
SetcompetencyAssessmentFeaturesData(featuresViewModel);
return RedirectToAction("CompetencyAssessmentSummary", new { competencyAssessmentId = featuresViewModel.ID,featuresViewModel.FrameworkId });
}

[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/Summary")]
public IActionResult CompetencyAssessmentSummary(int competencyAssessmentId, int? frameworkId = null)
{
if (competencyAssessmentService.GetSelfAssessmentStructure(competencyAssessmentId) != 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
if (competencyAssessmentId == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
var data = GetcompetencyAssessmentFeaturesData();
if (data == null) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 500 });
SetcompetencyAssessmentFeaturesData(data);
return View(data);
}
[HttpPost]
[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/Summary")]
public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesViewModel competency)
{
var data = GetcompetencyAssessmentFeaturesData();
if (data.ID == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
if (competencyAssessmentService.GetSelfAssessmentStructure(data.ID) != 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
var features = competencyAssessmentService.UpdateCompetencyAssessmentFeaturesTaskStatus(data.ID,
data.DescriptionStatus,
data.ProviderandCategoryStatus,
data.VocabularyStatus,
data.WorkingGroupStatus,
data.AllframeworkCompetenciesStatus);
if (!features) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 500 });
competencyAssessmentService.UpdateSelfAssessmentFromFramework(data.ID , data.FrameworkId );
var insertSelfAssessment = competencyAssessmentService.InsertSelfAssessmentStructure(data.ID, data.FrameworkId);
if (!insertSelfAssessment) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 500 });
multiPageFormService.ClearMultiPageFormData(MultiPageFormDataFeature.AddCustomWebForm("AssessmentFeaturesDataCWF"), TempData);
TempData.Clear();
return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId = competency.ID, competency.FrameworkId });
}

private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesViewModel data)
{
multiPageFormService.SetMultiPageFormData(
data,
MultiPageFormDataFeature.AddCustomWebForm("AssessmentFeaturesDataCWF"),
TempData
);
}

private CompetencyAssessmentFeaturesViewModel GetcompetencyAssessmentFeaturesData()
{
var data = multiPageFormService.GetMultiPageFormData<CompetencyAssessmentFeaturesViewModel>(
MultiPageFormDataFeature.AddCustomWebForm("AssessmentFeaturesDataCWF"),
TempData
).GetAwaiter().GetResult();
return data;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.Services;
using GDS.MultiPageFormData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
Expand All @@ -16,20 +17,23 @@ public partial class CompetencyAssessmentsController : Controller
private readonly IFrameworkNotificationService frameworkNotificationService;
private readonly ILogger<CompetencyAssessmentsController> logger;
private readonly IConfiguration config;
private readonly IMultiPageFormService multiPageFormService;
public CompetencyAssessmentsController(
ICompetencyAssessmentService competencyAssessmentService,
IFrameworkService frameworkService,
ICommonService commonService,
IFrameworkNotificationService frameworkNotificationService,
ILogger<CompetencyAssessmentsController> logger,
IConfiguration config)
IConfiguration config,
IMultiPageFormService multiPageFormService)
{
this.competencyAssessmentService = competencyAssessmentService;
this.frameworkService = frameworkService;
this.commonService = commonService;
this.frameworkNotificationService = frameworkNotificationService;
this.logger = logger;
this.config = config;
this.multiPageFormService = multiPageFormService;
}
public IActionResult Index()
{
Expand Down
Loading
Loading