public PartialViewResult addReadOnlySection(string sCounter, CollectionFormSection colFormSection) { ViewData["sNumber"] = sCounter; return PartialView("_addReadOnlySection", colFormSection); }
private void retrieveQuestionData() { DSC_OBS_DB_ENTITY db = new DSC_OBS_DB_ENTITY(); //To give Database access to this Class // Pull all the questions information for the selected Form in the correct order var formQuestions = db.OBS_COL_FORM_QUESTIONS.Include(o => o.OBS_FORM_SECTION).Where(x => x.obs_cft_id == cft_id).ToList().OrderBy(y => y.obs_col_form_quest_order); if (formQuestions.Count() > 0) { //Pupulate the Form Sections and Questions List only if there is question data for the selcted Form int sectionCounter = 0; string oldSectionName = "undefined"; string newSectionName = String.Empty; int questionCounter = 1; CollectionFormSection oSection = new CollectionFormSection(); foreach (OBS_COL_FORM_QUESTIONS q in formQuestions) { newSectionName = q.OBS_FORM_SECTION.obs_form_section_name; //If the section name has changed, then we are in a new section if (!newSectionName.Equals(oldSectionName)) // --- If this is a new Section --- { sectionCounter++; // If this is not the first section. Add the old Section to the List if (!oldSectionName.Equals("undefined")) { colFormSections.Add(oSection); } //Create a new Section from scratch oSection = new CollectionFormSection(); oSection.sectionNumber = sectionCounter; oSection.sectionName = q.OBS_FORM_SECTION.obs_form_section_name; oSection.sectionViewId = "viewSection" + oSection.sectionNumber.ToString(); } //Create New question, Populate the Info and Add it to the current Form section CollectionFormQuestion oQuestion = new CollectionFormQuestion(); oQuestion.cfq_id = q.obs_col_form_quest_id; oQuestion.cfq_questId = q.OBS_QUEST_ANS_TYPES.obs_question_id; oQuestion.cfq_order = q.obs_col_form_quest_order; oQuestion.cfq_seqInForm = questionCounter.ToString("00"); oQuestion.cfq_fullText = q.OBS_QUEST_ANS_TYPES.OBS_QUESTION.obs_question_full_text.Replace(System.Environment.NewLine.ToString(), "").Trim(); oQuestion.cfq_AT = q.OBS_QUEST_ANS_TYPES.OBS_ANS_TYPE.obs_ans_type_name; oQuestion.cfq_qatId = q.obs_qat_id; oQuestion.cfq_na_yn = q.obs_col_form_quest_na_yn; //oQuestion.cfq_SelectableAnswers = q.OBS_QUEST_ANS_TYPES.OBS_QUEST_SLCT_ANS.Where(item => item.obs_qsa_eff_st_dt <= DateTime.Now && item.obs_qsa_eff_end_dt > DateTime.Now).OrderBy(xx => xx.obs_qsa_order).Select(x => x.obs_qsa_text).ToList(); oQuestion.cfq_SelectableAnswers = q.OBS_QUEST_ANS_TYPES.OBS_QUEST_SLCT_ANS.OrderBy(xx => xx.obs_qsa_order).Select(x => x.obs_qsa_text).ToList(); // .... Populate the rest of the oQuestion properties oSection.colFormQuestionList.Add(oQuestion); // reset the name of the old section indicator oldSectionName = newSectionName; questionCounter++; } // End of For-each question loop //Finally add the last populated section to the section List colFormSections.Add(oSection); } }