diff --git a/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs b/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs index b6ff269935..0b1675fcaf 100644 --- a/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs @@ -116,6 +116,8 @@ bool UpdateSelfAssessments(int competencyAssessmentId, void InsertSelfAssessmentReview(int competencyAssessmentId, int selfAssessmentCollaboratorID, bool required); int InsertComment(int selfAssessmentID, int adminId, string comment, int? replyToCommentId); int InsertCompetencySelfAssessmentReview(int reviewId); + void RetireCompetencyAssessment(int competencyAssessmentId, DateTime? retirementDate, string retirementReason); + //DELETE DATA bool RemoveFrameworkCompetenciesFromAssessment(int competencyAssessmentId, int frameworkId); @@ -143,6 +145,8 @@ public class CompetencyAssessmentDataService : ICompetencyAssessmentDataService sa.ManageOptionalCompetenciesPrompt, sa.IncludeLearnerDeclarationPrompt, sa.IncludesSignposting, sa.LinearNavigation, sa.UseDescriptionExpanders, sa.QuestionLabel, sa.ReviewerCommentsLabel, sa.SupervisorSelfAssessmentReview, sa.SupervisorResultsReview, sar.ID AS SelfAssessmentReviewID, sa.SignOffSupervisorStatement, sa.SignOffRequestorStatement, + sa.RetirementReason, + sa.RetirementDate, sar.SelfAssessmentCommentID"; private const string SelfAssessmentFields = @@ -1773,6 +1777,17 @@ OUTPUT INSERTED.ID return id; } + public void RetireCompetencyAssessment(int competencyAssessmentId, DateTime? retirementDate, string retirementReason) + { + // Example using Dapper + connection.Execute( + @"UPDATE SelfAssessments + SET RetirementDate = @retirementDate, RetirementReason = @retirementReason + WHERE ID = @competencyAssessmentId", + new { retirementDate, retirementReason, competencyAssessmentId } + ); + } + public bool UpdateCompetencyAssessmentReviewTaskStatus(int assessmentId, bool taskStatus) { var numberOfAffectedRows = connection.Execute( diff --git a/DigitalLearningSolutions.Data/Models/CompetencyAssessments/CompetencyAssessmentBase.cs b/DigitalLearningSolutions.Data/Models/CompetencyAssessments/CompetencyAssessmentBase.cs index 58a11866d7..bf279ad1f5 100644 --- a/DigitalLearningSolutions.Data/Models/CompetencyAssessments/CompetencyAssessmentBase.cs +++ b/DigitalLearningSolutions.Data/Models/CompetencyAssessments/CompetencyAssessmentBase.cs @@ -1,5 +1,6 @@ namespace DigitalLearningSolutions.Data.Models.CompetencyAssessments { + using System; using System.ComponentModel.DataAnnotations; public class CompetencyAssessmentBase { @@ -36,6 +37,9 @@ public class CompetencyAssessmentBase public string? SignOffSupervisorStatement { get; set; } public int? SelfAssessmentReviewID { get; set; } public int? SelfAssessmentCommentID { get; set; } + public DateTime? RetirementDate { get; set; } + public string? RetirementReason { get; set; } + } } diff --git a/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs b/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs index b353490b19..89dea213bf 100644 --- a/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs +++ b/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs @@ -1,5 +1,6 @@ namespace DigitalLearningSolutions.Web.Controllers.CompetencyAssessmentsController { + using System; using DigitalLearningSolutions.Data.Enums; using DigitalLearningSolutions.Data.Extensions; using DigitalLearningSolutions.Data.Models.CompetencyAssessments; @@ -1735,6 +1736,42 @@ public IActionResult PreviewConfirm(CompetencyAssessmentPreviewViewModel model) return RedirectToAction("SelfAssessment", "LearningPortal", new { selfAssessmentId = model.CompetencyAssessmentId }); } + [HttpGet] + [Route("/Self-Assessment/{competencyAssessmentId}/Retire")] + public IActionResult RetireCompetencyAssessment(int competencyAssessmentId) + { + var adminId = GetAdminID(); + var assessment = competencyAssessmentService.GetCompetencyAssessmentBaseById(competencyAssessmentId, adminId); + if (assessment == null) return StatusCode(404); + + var model = new RetireCompetencyAssessmentViewModel(competencyAssessmentId, assessment); + return View("RetireCompetencyAssessment", model); + } + + [HttpPost] + [Route("/Self-Assessment/{competencyAssessmentId}/Retire")] + public IActionResult RetireCompetencyAssessment(RetireCompetencyAssessmentViewModel model, int competencyAssessmentId) + { + if (!ModelState.IsValid) + { + return View("RetireCompetencyAssessment", model); + } + + model.RetirementDate = new DateTime(model.Year!.Value, model.Month!.Value, model.Day!.Value); + + + var adminId = GetAdminID(); + competencyAssessmentService.RetireCompetencyAssessment( + model.CompetencyAssessmentId, + model.RetirementDate, + model.RetirementReason!, + adminId + ); + + return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId = model.CompetencyAssessmentId }); + } + + private void SetManagesupervisionData(ManagesupervisionViewModel data) { multiPageFormService.SetMultiPageFormData( diff --git a/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs b/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs index ab2bffac1b..16835c2726 100644 --- a/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs +++ b/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs @@ -5,6 +5,7 @@ using DigitalLearningSolutions.Web.ViewModels.Frameworks; using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Centre.Reports; using DocumentFormat.OpenXml.Drawing.Charts; +using System; using System.Collections.Generic; using System.Linq; @@ -122,6 +123,8 @@ bool UpdateSelfAssessments(int competencyAssessmentId, void RemoveCollaboratorFromCompetencyAssessment(int competencyAssessmentId, int id); CompetencyAssessmentCollaboratorNotification? GetCollaboratorNotification(int id, int invitedByAdminId); bool HasCompetencyWithSignpostedLearning(int competencyAssessmentId); + void RetireCompetencyAssessment(int competencyAssessmentId, DateTime? RetirementDate, string retirementReason, int adminId); + } public class CompetencyAssessmentService : ICompetencyAssessmentService { @@ -589,5 +592,21 @@ public bool UpdateCompetencyAssessmentReviewTaskStatus(int assessmentId, bool t { return competencyAssessmentDataService.UpdateCompetencyAssessmentReviewTaskStatus(assessmentId, taskStatus); } + public void RetireCompetencyAssessment(int competencyAssessmentId, DateTime? RetirementDate, string retirementReason, int adminId) + { + // Persist retirement info + competencyAssessmentDataService.RetireCompetencyAssessment(competencyAssessmentId, RetirementDate, retirementReason); + + // Update publish status + var today = DateTime.UtcNow.Date; + int status; + if (RetirementDate > today) + status = 4; // Scheduled for retirement (amber) + else + status = 5; // Retired (red) + + competencyAssessmentDataService.UpdateCompetencyAssessmentPublishStatus(competencyAssessmentId, status, adminId); + } + } } diff --git a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ManageCompetencyAssessmentViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ManageCompetencyAssessmentViewModel.cs index f62cf5d764..2ec27ea90d 100644 --- a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ManageCompetencyAssessmentViewModel.cs +++ b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ManageCompetencyAssessmentViewModel.cs @@ -1,5 +1,6 @@ using DigitalLearningSolutions.Data.Models.CompetencyAssessments; using DigitalLearningSolutions.Web.Helpers; +using System; namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments { @@ -20,6 +21,7 @@ bool hasCompetencies VocabularyPlural = FrameworkVocabularyHelper.VocabularyPlural(competencyAssessmentBase.Vocabulary); SelfAssessmentReviewID = competencyAssessmentBase.SelfAssessmentReviewID; SelfAssessmentCommentID = competencyAssessmentBase.SelfAssessmentCommentID; + RetirementDate = competencyAssessmentBase.RetirementDate; } public string CompetencyAssessmentName { get; set; } public int PublishStatusID { get; set; } @@ -30,5 +32,6 @@ bool hasCompetencies public int? SelfAssessmentReviewID { get; set; } public int? SelfAssessmentCommentID { get; set; } public bool HasCompetencies { get; set; } + public DateTime? RetirementDate { get; set; } } } diff --git a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/RetireCompetencyAssessmentViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/RetireCompetencyAssessmentViewModel.cs new file mode 100644 index 0000000000..372bb4bf26 --- /dev/null +++ b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/RetireCompetencyAssessmentViewModel.cs @@ -0,0 +1,35 @@ +using DocumentFormat.OpenXml.Drawing.Charts; +using System; +using System.ComponentModel.DataAnnotations; +using DigitalLearningSolutions.Data.Models.CompetencyAssessments; + +namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments +{ + public class RetireCompetencyAssessmentViewModel + { + public int CompetencyAssessmentId { get; set; } + + [Required(ErrorMessage = "Enter a reason for retirement")] + [StringLength(2000, ErrorMessage = "Reason must be 2000 characters or fewer")] + public string? RetirementReason { get; set; } + + public DateTime? RetirementDate { get; set; } + public int? Day { get; set; } + public int? Month { get; set; } + public int? Year { get; set; } + public RetireCompetencyAssessmentViewModel(int competencyAssessmentId, CompetencyAssessmentBase? assessment) + { + if (assessment?.RetirementDate != null) + { + Day = assessment.RetirementDate.Value.Day; + Month = assessment.RetirementDate.Value.Month; + Year = assessment.RetirementDate.Value.Year; + } + RetirementReason = assessment.RetirementReason; + CompetencyAssessmentId = competencyAssessmentId; + } + public RetireCompetencyAssessmentViewModel() + { + } + } +} diff --git a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ManageCompetencyAssessment.cshtml b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ManageCompetencyAssessment.cshtml index a63ebf6644..ee0ff02bcb 100644 --- a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ManageCompetencyAssessment.cshtml +++ b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ManageCompetencyAssessment.cshtml @@ -55,9 +55,29 @@