/// <summary> /// Assembles a response consisting of maturity settings for the assessment /// as well as the question set in its hierarchy of domains, practices, etc. /// </summary> /// <param name="assessmentId"></param> public MaturityResponse GetMaturityQuestions(int assessmentId, bool isAcetInstallation, bool fill) { var response = new MaturityResponse(); using (var db = new CSET_Context()) { if (fill) { db.FillEmptyMaturityQuestionsForAnalysis(assessmentId); } var myModel = ProcessModelDefaults(db, assessmentId, isAcetInstallation); var myModelDefinition = db.MATURITY_MODELS.Where(x => x.Maturity_Model_Id == myModel.model_id).FirstOrDefault(); if (myModelDefinition == null) { return(response); } response.ModelName = myModelDefinition.Model_Name; response.QuestionsAlias = myModelDefinition.Questions_Alias ?? "Questions"; if (myModelDefinition.Answer_Options != null) { response.AnswerOptions = myModelDefinition.Answer_Options.Split(',').ToList(); response.AnswerOptions.ForEach(x => x = x.Trim()); } response.MaturityTargetLevel = this.GetMaturityTargetLevel(assessmentId, db); if (response.ModelName == "ACET") { response.OverallIRP = new ACETDashboardManager().GetOverallIrpNumber(assessmentId); response.MaturityTargetLevel = response.OverallIRP; } // get the levels and their display names for this model response.Levels = this.GetMaturityLevelsForModel(myModel.model_id, response.MaturityTargetLevel, db); // Get all maturity questions for the model regardless of level. // The user may choose to see questions above the target level via filtering. var questions = db.MATURITY_QUESTIONS .Include(x => x.Maturity_LevelNavigation) .Where(q => myModel.model_id == q.Maturity_Model_Id).ToList(); // Get all MATURITY answers for the assessment var answers = from a in db.ANSWER.Where(x => x.Assessment_Id == assessmentId && x.Question_Type == "Maturity") from b in db.VIEW_QUESTIONS_STATUS.Where(x => x.Answer_Id == a.Answer_Id).DefaultIfEmpty() select new FullAnswer() { a = a, b = b }; // Get all subgroupings for this maturity model var allGroupings = db.MATURITY_GROUPINGS .Include(x => x.Type) .Where(x => x.Maturity_Model_Id == myModel.model_id).ToList(); // Recursively build the grouping/question hierarchy var tempModel = new MaturityGrouping(); BuildSubGroupings(tempModel, null, allGroupings, questions, answers.ToList()); //GRAB all the domain remarks and assign them if necessary Dictionary <int, MATURITY_DOMAIN_REMARKS> domainRemarks = db.MATURITY_DOMAIN_REMARKS.Where(x => x.Assessment_Id == assessmentId) .ToDictionary(x => x.Grouping_ID, x => x); foreach (MaturityGrouping g in tempModel.SubGroupings) { MATURITY_DOMAIN_REMARKS dm; if (domainRemarks.TryGetValue(g.GroupingID, out dm)) { g.DomainRemark = dm.DomainRemarks; } } response.Groupings = tempModel.SubGroupings; // Add any glossary terms response.Glossary = this.GetGlossaryEntries(myModel.model_id); } return(response); }
/// <summary> /// Recursive method that builds subgroupings for the specified group. /// It also attaches any questions pertinent to this group. /// </summary> private void BuildSubGroupings(MaturityGrouping g, int?parentID, List <MATURITY_GROUPINGS> allGroupings, List <MATURITY_QUESTIONS> questions, List <FullAnswer> answers) { var mySubgroups = allGroupings.Where(x => x.Parent_Id == parentID).OrderBy(x => x.Sequence).ToList(); if (mySubgroups.Count == 0) { return; } foreach (var sg in mySubgroups) { var newGrouping = new MaturityGrouping() { GroupingID = sg.Grouping_Id, GroupingType = sg.Type.Grouping_Type_Name, Title = sg.Title, Description = sg.Description, Abbreviation = sg.Abbreviation }; g.SubGroupings.Add(newGrouping); // are there any questions that belong to this grouping? var myQuestions = questions.Where(x => x.Grouping_Id == newGrouping.GroupingID).ToList(); var parentQuestionIDs = myQuestions.Select(x => x.Parent_Question_Id).Distinct().ToList(); foreach (var myQ in myQuestions) { FullAnswer answer = answers.Where(x => x.a.Question_Or_Requirement_Id == myQ.Mat_Question_Id).FirstOrDefault(); var qa = new QuestionAnswer() { DisplayNumber = myQ.Question_Title, QuestionId = myQ.Mat_Question_Id, ParentQuestionId = myQ.Parent_Question_Id, Sequence = myQ.Sequence, QuestionType = "Maturity", QuestionText = myQ.Question_Text.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>"), Answer = answer?.a.Answer_Text, AltAnswerText = answer?.a.Alternate_Justification, Comment = answer?.a.Comment, Feedback = answer?.a.Feedback, MarkForReview = answer?.a.Mark_For_Review ?? false, Reviewed = answer?.a.Reviewed ?? false, Is_Maturity = true, MaturityLevel = myQ.Maturity_LevelNavigation.Level, MaturityLevelName = myQ.Maturity_LevelNavigation.Level_Name, IsParentQuestion = parentQuestionIDs.Contains(myQ.Mat_Question_Id), SetName = string.Empty }; if (answer != null) { TinyMapper.Bind <VIEW_QUESTIONS_STATUS, QuestionAnswer>(); TinyMapper.Map(answer.b, qa); } newGrouping.Questions.Add(qa); } newGrouping.Questions.Sort((a, b) => a.Sequence.CompareTo(b.Sequence)); // Recurse down to build subgroupings BuildSubGroupings(newGrouping, newGrouping.GroupingID, allGroupings, questions, answers); } }
public List <MatAnsweredQuestionDomain> getAnsweredQuestionList(int assessmentId) { List <BasicReportData.RequirementControl> controls = new List <BasicReportData.RequirementControl>(); //select* from ANSWER a //join MATURITY_QUESTIONS q on a.Question_Or_Requirement_Id = q.Mat_Question_Id //where a.Assessment_Id = 2357 and a.question_type = 'Maturity' and a.Answer_Text = 'N' using (var db = new CSET_Context()) { var myModel = db.AVAILABLE_MATURITY_MODELS .Include(x => x.model_) .Where(x => x.Assessment_Id == assessmentId).FirstOrDefault(); var questions = db.MATURITY_QUESTIONS.Where(q => myModel.model_id == q.Maturity_Model_Id).ToList(); // Get all MATURITY answers for the assessment var answers = from a in db.ANSWER.Where(x => x.Assessment_Id == assessmentId && x.Question_Type == "Maturity") from b in db.VIEW_QUESTIONS_STATUS.Where(x => x.Answer_Id == a.Answer_Id).DefaultIfEmpty() select new FullAnswer() { a = a, b = b }; // Get all subgroupings for this maturity model var allGroupings = db.MATURITY_GROUPINGS .Include(x => x.Type) .Where(x => x.Maturity_Model_Id == myModel.model_id).ToList(); // Recursively build the grouping/question hierarchy var questionGrouping = new MaturityGrouping(); BuildSubGroupings(questionGrouping, null, allGroupings, questions, answers.ToList()); var maturityDomains = new List <MatAnsweredQuestionDomain>(); // ToDo: Refactor the following stucture of loops foreach (var domain in questionGrouping.SubGroupings) { var newDomain = new MatAnsweredQuestionDomain() { Title = domain.Title, AssessmentFactors = new List <MaturityAnsweredQuestionsAssesment>() }; foreach (var assesmentFactor in domain.SubGroupings) { var newAssesmentFactor = new MaturityAnsweredQuestionsAssesment() { Title = assesmentFactor.Title, Components = new List <MaturityAnsweredQuestionsComponent>() }; foreach (var componenet in assesmentFactor.SubGroupings) { var newComponent = new MaturityAnsweredQuestionsComponent() { Title = componenet.Title, Questions = new List <MaturityAnsweredQuestions>() }; foreach (var question in componenet.Questions) { if (question.Answer != null) { var newQuestion = new MaturityAnsweredQuestions() { Title = question.DisplayNumber, QuestionText = question.QuestionText, AnswerText = question.Answer, }; if (question.Comment != null) { newQuestion.Comments = "Yes"; } else { newQuestion.Comments = "No"; } if (question.MaturityLevel == 6) { newQuestion.MaturityLevel = "ADV"; } else if (question.MaturityLevel == 7) { newQuestion.MaturityLevel = "B"; } else if (question.MaturityLevel == 8) { newQuestion.MaturityLevel = "E"; } else if (question.MaturityLevel == 9) { newQuestion.MaturityLevel = "INN"; } else if (question.MaturityLevel == 10) { newQuestion.MaturityLevel = "INT"; } else { newQuestion.MaturityLevel = ""; } newComponent.Questions.Add(newQuestion); } } if (newComponent.Questions.Count > 0) { newAssesmentFactor.Components.Add(newComponent); } } if (newAssesmentFactor.Components.Count > 0) { newDomain.AssessmentFactors.Add(newAssesmentFactor); } } if (newDomain.AssessmentFactors.Count > 0) { maturityDomains.Add(newDomain); } } return(maturityDomains); } }