diff --git a/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs b/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs index f284f5d455..d9b4b25a88 100644 --- a/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs @@ -130,9 +130,9 @@ bool zeroBased IEnumerable GetAllCompetenciesForAdminId(string name, int adminId); - int InsertCompetency(string name, string? description, int adminId); + int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false); - int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false); + int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool addDefaultQuestions = true); int AddCollaboratorToFramework(int frameworkId, string userEmail, bool canModify, int? centreID); @@ -618,7 +618,7 @@ FROM [FrameworkCompetencyGroups] return existingId; } - public int InsertCompetency(string name, string? description, int adminId) + public int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false) { if ((name.Length == 0) | (adminId < 1)) { @@ -630,10 +630,10 @@ public int InsertCompetency(string name, string? description, int adminId) description = (description?.Trim() == "" ? null : description); var existingId = connection.QuerySingle( - @"INSERT INTO Competencies ([Name], [Description], UpdatedByAdminID) + @"INSERT INTO Competencies ([Name], [Description], UpdatedByAdminID, AlwaysShowDescription) OUTPUT INSERTED.Id - VALUES (@name, @description, @adminId)", - new { name, description, adminId } + VALUES (@name, @description, @adminId, @alwaysShowDescription)", + new { name, description, adminId, alwaysShowDescription } ); return existingId; @@ -644,7 +644,7 @@ public int InsertFrameworkCompetency( int? frameworkCompetencyGroupID, int adminId, int frameworkId, - bool alwaysShowDescription = false + bool addDefaultQuestions = true ) { if ((competencyId < 1) | (adminId < 1) | (frameworkId < 1)) @@ -706,8 +706,10 @@ FROM [FrameworkCompetencies] new { competencyId, frameworkCompetencyGroupID } ); } - - AddDefaultQuestionsToCompetency(competencyId, frameworkId); + if(addDefaultQuestions) + { + AddDefaultQuestionsToCompetency(competencyId, frameworkId); + } return existingId; } diff --git a/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs b/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs index b2582144bb..b3e8c8837b 100644 --- a/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs +++ b/DigitalLearningSolutions.Web/Controllers/FrameworksController/ImportCompetencies.cs @@ -180,15 +180,16 @@ public IActionResult AddAssessmentQuestions() public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model) { var data = GetBulkUploadData(); - data.AddDefaultAssessmentQuestions = model.AddDefaultAssessmentQuestions; + if (model.AddDefaultAssessmentQuestions) { - data.DefaultQuestionIDs = model.DefaultAssessmentQuestionIDs; + data.DefaultQuestionIDs = model.DefaultAssessmentQuestionIDs ?? []; } else { data.DefaultQuestionIDs = []; } + data.AddDefaultAssessmentQuestions = (data.DefaultQuestionIDs.Count > 0 && model.AddDefaultAssessmentQuestions); data.AddCustomAssessmentQuestion = model.AddCustomAssessmentQuestion; if (model.AddCustomAssessmentQuestion) { @@ -198,9 +199,8 @@ public IActionResult AddAssessmentQuestions(AddAssessmentQuestionsFormData model { data.CustomAssessmentQuestionID = null; } - if (data.CompetenciesToUpdateCount > 0) + if (data.CompetenciesToUpdateCount > 0 && (data.DefaultQuestionIDs.Count + (data.CustomAssessmentQuestionID != null ? 1 : 0) > 0)) { - data.AddAssessmentQuestionsOption = 2; setBulkUploadData(data); return RedirectToAction("AddQuestionsToWhichCompetencies", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName }); } @@ -260,11 +260,6 @@ public IActionResult ImportSummarySubmit() var workbook = new XLWorkbook(filePath); var results = importCompetenciesFromFileService.ProcessCompetenciesFromFile(workbook, adminId, data.FrameworkId, data.FrameworkVocubulary, data.ReorderCompetenciesOption, data.AddAssessmentQuestionsOption, data.AddCustomAssessmentQuestion ? (int)data.CustomAssessmentQuestionID : 0, data.AddDefaultAssessmentQuestions ? data.DefaultQuestionIDs : []); data.ImportCompetenciesResult = results; - //TO DO apply ordering changes if required: - if (data.ReorderCompetenciesOption == 2 && data.CompetenciesToReorderCount > 0) - { - - } setBulkUploadData(data); return RedirectToAction("UploadResults", "Frameworks", new { frameworkId = data.FrameworkId, tabname = data.TabName }); } diff --git a/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs b/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs index 83b8bc8532..0fd476caa3 100644 --- a/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs +++ b/DigitalLearningSolutions.Web/Models/BulkCompetenciesData.cs @@ -32,7 +32,7 @@ public BulkCompetenciesData(DetailFramework framework, int adminUserId, string c public bool AddCustomAssessmentQuestion { get; set; } = false; public List DefaultQuestionIDs { get; set; } = []; public int? CustomAssessmentQuestionID { get; set; } - public int AddAssessmentQuestionsOption { get; set; } = 1; //1 = only added, 2 = added and updated, 3 = all uploaded + public int AddAssessmentQuestionsOption { get; set; } = 2; //1 = only added, 2 = added and updated, 3 = all uploaded public int CompetenciesToProcessCount { get; set; } public int CompetenciesToAddCount { get; set; } public int CompetenciesToUpdateCount { get; set; } diff --git a/DigitalLearningSolutions.Web/Services/FrameworkService.cs b/DigitalLearningSolutions.Web/Services/FrameworkService.cs index 7dadad0708..e0b5306bf3 100644 --- a/DigitalLearningSolutions.Web/Services/FrameworkService.cs +++ b/DigitalLearningSolutions.Web/Services/FrameworkService.cs @@ -120,11 +120,11 @@ bool zeroBased int InsertCompetencyGroup(string groupName, string? groupDescription, int adminId, int? frameworkId = null); - int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false); + int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool addDefaultQuestions = true); IEnumerable GetAllCompetenciesForAdminId(string name, int adminId); - int InsertCompetency(string name, string? description, int adminId); + int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false); int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId); @@ -594,9 +594,9 @@ public int InsertComment(int frameworkId, int adminId, string comment, int? repl return frameworkDataService.InsertComment(frameworkId, adminId, comment, replyToCommentId); } - public int InsertCompetency(string name, string? description, int adminId) + public int InsertCompetency(string name, string? description, int adminId, bool alwaysShowDescription = false) { - return frameworkDataService.InsertCompetency(name, description, adminId); + return frameworkDataService.InsertCompetency(name, description, adminId, alwaysShowDescription); } public int InsertCompetencyGroup(string groupName, string? groupDescription, int adminId, int? frameworkId) @@ -604,9 +604,9 @@ public int InsertCompetencyGroup(string groupName, string? groupDescription, int return frameworkDataService.InsertCompetencyGroup(groupName, groupDescription, adminId, frameworkId); } - public int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool alwaysShowDescription = false) + public int InsertFrameworkCompetency(int competencyId, int? frameworkCompetencyGroupID, int adminId, int frameworkId, bool addDefaultQuestions = true) { - return frameworkDataService.InsertFrameworkCompetency(competencyId, frameworkCompetencyGroupID, adminId, frameworkId, alwaysShowDescription); + return frameworkDataService.InsertFrameworkCompetency(competencyId, frameworkCompetencyGroupID, adminId, frameworkId, addDefaultQuestions); } public int InsertFrameworkCompetencyGroup(int groupId, int frameworkID, int adminId) diff --git a/DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs b/DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs index 82bda9b6b9..d7aa831d6c 100644 --- a/DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs +++ b/DigitalLearningSolutions.Web/Services/ImportCompetenciesFromFileService.cs @@ -211,10 +211,10 @@ CompetencyTableRow competencyRow else { //Check if competency already exists in framework competency group and add if not - newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminId); + newCompetencyId = frameworkService.InsertCompetency(competencyRow.Competency, competencyRow.CompetencyDescription, adminId, competencyRow.AlwaysShowDescription ?? false); if (newCompetencyId > 0) { - newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId, competencyRow.AlwaysShowDescription ?? false); //including always show desc flag + newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId, false); if (newFrameworkCompetencyId > maxFrameworkCompetencyId) { competencyRow.RowStatus = (competencyRow.RowStatus == RowStatus.CompetencyGroupInserted ? RowStatus.CompetencyGroupAndCompetencyInserted : RowStatus.CompetencyInserted); diff --git a/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs index 76a9fa4e68..ce55e56f6c 100644 --- a/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs +++ b/DigitalLearningSolutions.Web/ViewModels/Frameworks/Import/AddQuestionsToWhichCompetenciesViewModel.cs @@ -1,5 +1,6 @@ using DigitalLearningSolutions.Web.Helpers; using System.Collections.Generic; +using System.Linq; using System.Runtime.Versioning; namespace DigitalLearningSolutions.Web.ViewModels.Frameworks.Import diff --git a/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml b/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml index eef8dbabe8..8e3b9ebdf9 100644 --- a/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml +++ b/DigitalLearningSolutions.Web/Views/Frameworks/Developer/Import/AddQuestionsToWhichCompetencies.cshtml @@ -47,7 +47,7 @@ @if (Model.CompetenciesToAddCount > 0) {
- + @@ -57,7 +57,7 @@
}
- + @@ -66,7 +66,7 @@
- +