From 2819ac85057439a1999f5f6f25bf3057f70f51d6 Mon Sep 17 00:00:00 2001 From: Daniel Manta Date: Wed, 10 Aug 2022 18:08:18 +0100 Subject: [PATCH 1/2] DLSV2-538 Save zero as Result on SelfAssessmentResults table when no option is selected as result for an assessment question --- .../CompetencyDataService.cs | 2 +- .../SelfAssessment.cs | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs index 701fccb03e..6d27d5f0a0 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs @@ -338,7 +338,7 @@ FROM AssessmentQuestions var minValue = assessmentQuestion.MinValue; var maxValue = assessmentQuestion.MaxValue; - if (result != null) + if (result > 0) { if (result < minValue || result > maxValue) { diff --git a/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs b/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs index 94b005f1e6..f15314367c 100644 --- a/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs +++ b/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs @@ -161,17 +161,14 @@ public IActionResult SelfAssessmentCompetency( foreach (var assessmentQuestion in assessmentQuestions) { - if (assessmentQuestion.Result != null || assessmentQuestion.SupportingComments != null) - { - selfAssessmentService.SetResultForCompetency( - competencyId, - assessment.Id, - candidateId, - assessmentQuestion.Id, - assessmentQuestion.Result, - assessmentQuestion.SupportingComments - ); - } + selfAssessmentService.SetResultForCompetency( + competencyId, + assessment.Id, + candidateId, + assessmentQuestion.Id, + assessmentQuestion.Result ?? 0, + assessmentQuestion.SupportingComments + ); } selfAssessmentService.SetUpdatedFlag(selfAssessmentId, candidateId, true); From d880dfc838abd5e053b27f1217071cfcee1f90a7 Mon Sep 17 00:00:00 2001 From: Daniel Manta Date: Wed, 31 Aug 2022 00:36:48 +0100 Subject: [PATCH 2/2] DLSV2-538 Save null as Result into SelfAssessmentResults table when no option is selected as result for an assessment question --- ...02208301100_AllowNullSelfAssessmentResults.cs | 16 ++++++++++++++++ .../CompetencyDataService.cs | 15 ++++++--------- .../LearningPortalController/SelfAssessment.cs | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 DigitalLearningSolutions.Data.Migrations/202208301100_AllowNullSelfAssessmentResults.cs diff --git a/DigitalLearningSolutions.Data.Migrations/202208301100_AllowNullSelfAssessmentResults.cs b/DigitalLearningSolutions.Data.Migrations/202208301100_AllowNullSelfAssessmentResults.cs new file mode 100644 index 0000000000..12482323cc --- /dev/null +++ b/DigitalLearningSolutions.Data.Migrations/202208301100_AllowNullSelfAssessmentResults.cs @@ -0,0 +1,16 @@ +namespace DigitalLearningSolutions.Data.Migrations +{ + using FluentMigrator; + [Migration(202208301100)] + public class AllowNullSelfAssessmentResults : Migration + { + public override void Up() + { + Alter.Table("SelfAssessmentResults").AlterColumn("Result").AsInt32().Nullable(); + } + public override void Down() + { + Alter.Table("SelfAssessmentResults").AlterColumn("Result").AsInt32().NotNullable().SetExistingRowsTo(0); + } + } +} diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs index 6d27d5f0a0..041029c521 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CompetencyDataService.cs @@ -338,16 +338,13 @@ FROM AssessmentQuestions var minValue = assessmentQuestion.MinValue; var maxValue = assessmentQuestion.MaxValue; - if (result > 0) + if (result < minValue || result > maxValue) { - if (result < minValue || result > maxValue) - { - logger.LogWarning( - "Not saving self assessment result as result is invalid. " + - $"{PrintResult(competencyId, selfAssessmentId, candidateId, assessmentQuestionId, result)}" - ); - return; - } + logger.LogWarning( + "Not saving self assessment result as result is invalid. " + + $"{PrintResult(competencyId, selfAssessmentId, candidateId, assessmentQuestionId, result)}" + ); + return; } var numberOfAffectedRows = connection.Execute( diff --git a/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs b/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs index f15314367c..4362a14a34 100644 --- a/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs +++ b/DigitalLearningSolutions.Web/Controllers/LearningPortalController/SelfAssessment.cs @@ -166,7 +166,7 @@ public IActionResult SelfAssessmentCompetency( assessment.Id, candidateId, assessmentQuestion.Id, - assessmentQuestion.Result ?? 0, + assessmentQuestion.Result, assessmentQuestion.SupportingComments ); }