public void StoreSubcategoryAnswers([FromBody] SubCategoryAnswers subCatAnswers) { int assessmentId = Auth.AssessmentForUser(); QuestionsManager qm = new QuestionsManager(assessmentId); qm.StoreSubcategoryAnswers(subCatAnswers); }
/// <summary> /// Persists a single answer to the SUB_CATEGORY_ANSWERS table for the 'block answer', /// and flips all of the constituent questions' answers. /// </summary> public void StoreSubcategoryAnswers(SubCategoryAnswers subCatAnswerBlock) { if (subCatAnswerBlock == null) { return; } // SUB_CATEGORY_ANSWERS var db = new CSET_Context(); // Get the USCH so that we will know the Heading_Pair_Id var usch = db.UNIVERSAL_SUB_CATEGORY_HEADINGS.Where(u => u.Question_Group_Heading_Id == subCatAnswerBlock.GroupHeadingId && u.Universal_Sub_Category_Id == subCatAnswerBlock.SubCategoryId).FirstOrDefault(); var subCatAnswer = db.SUB_CATEGORY_ANSWERS.Where(sca => sca.Assessement_Id == assessmentID && sca.Heading_Pair_Id == usch.Heading_Pair_Id).FirstOrDefault(); if (subCatAnswer == null) { subCatAnswer = new SUB_CATEGORY_ANSWERS(); } subCatAnswer.Assessement_Id = assessmentID; subCatAnswer.Heading_Pair_Id = usch.Heading_Pair_Id; subCatAnswer.Answer_Text = subCatAnswerBlock.SubCategoryAnswer; db.SUB_CATEGORY_ANSWERS.AddOrUpdate(subCatAnswer, x => x.Assessement_Id, x => x.Heading_Pair_Id); db.SaveChanges(); AssessmentUtil.TouchAssessment(assessmentID); // loop and store all of the subcategory's answers foreach (Answer ans in subCatAnswerBlock.Answers) { if (String.IsNullOrWhiteSpace(ans.QuestionType)) { if (ans.Is_Component) { ans.QuestionType = "Component"; } if (ans.Is_Maturity) { ans.QuestionType = "Maturity"; } if (ans.Is_Requirement) { ans.QuestionType = "Requirement"; } if (!ans.Is_Requirement && !ans.Is_Maturity && !ans.Is_Component) { ans.QuestionType = "Question"; } } StoreAnswer(ans); } }
/// <summary> /// Persists a single answer to the SUB_CATEGORY_ANSWERS table for the 'block answer', /// and flips all of the constituent questions' answers. /// </summary> public void StoreSubcategoryAnswers(SubCategoryAnswers subCatAnswerBlock) { if (subCatAnswerBlock == null) { return; } // SUB_CATEGORY_ANSWERS var db = new CSET_Context(); // Get the USCH so that we will know the Heading_Pair_Id var usch = db.UNIVERSAL_SUB_CATEGORY_HEADINGS.Where(u => u.Question_Group_Heading_Id == subCatAnswerBlock.GroupHeadingId && u.Universal_Sub_Category_Id == subCatAnswerBlock.SubCategoryId).FirstOrDefault(); var subCatAnswer = db.SUB_CATEGORY_ANSWERS.Where(sca => sca.Assessement_Id == _assessmentId && sca.Heading_Pair_Id == usch.Heading_Pair_Id).FirstOrDefault(); if (subCatAnswer == null) { subCatAnswer = new SUB_CATEGORY_ANSWERS(); } subCatAnswer.Assessement_Id = _assessmentId; subCatAnswer.Heading_Pair_Id = usch.Heading_Pair_Id; subCatAnswer.Answer_Text = subCatAnswerBlock.SubCategoryAnswer; db.SUB_CATEGORY_ANSWERS.AddOrUpdate(subCatAnswer, x => x.Assessement_Id, x => x.Heading_Pair_Id); db.SaveChanges(); AssessmentUtil.TouchAssessment(_assessmentId); // loop and store all of the subcategory's answers foreach (Answer ans in subCatAnswerBlock.Answers) { StoreAnswer(ans); } }