public void SurveyQuestionSelected(object sender, EventArgs e)
        {
            var ddlSurveyQuestion = sender as DropDownList;
            var listView          = Page.FindControlRecursive("InnerListView") as ListView;

            if (ddlSurveyQuestion == null || listView == null)
            {
                return;
            }

            if (ddlSurveyQuestion.SelectedValue == "-1" || ddlSurveyQuestion.SelectedValue == "-100")
            {
                listView.DataSource = null;
                listView.DataBind();
                QuestionSelected?.Invoke(this, EventArgs.Empty);

                return;
            }

            var survey = ContentRepository.Content.Create(PortalContext.Current.ContextNode);

            if (!(survey.Fields["FieldSettingContents"] is ReferenceField customFields))
            {
                return;
            }

            var questions = customFields.OriginalValue as List <ContentRepository.Storage.Node>;

            var selectedQuestion = from q in questions where q.Name == ddlSurveyQuestion.SelectedValue select q;
            var pageBreaks       = (from q in questions where q.NodeType.Name == "PageBreakFieldSetting" select q).Count();
            var choiceFs         = (ChoiceFieldSetting)((FieldSettingContent)selectedQuestion.First()).FieldSetting;
            var answers          = choiceFs.Options;
            var rules            = answers.Select(opt => new SurveyRule(opt.Text, opt.Value, "", pageBreaks)).ToList();

            if (choiceFs.AllowExtraValue.HasValue && choiceFs.AllowExtraValue.Value && rules.All(sr => sr.AnswerId != SurveyRule.EXTRAVALUEID))
            {
                // add extra value as a possible option
                rules.Add(new SurveyRule(SurveyRule.GetExtraValueText(), SurveyRule.EXTRAVALUEID, "", pageBreaks));
            }

            listView.DataSource = rules;
            listView.DataBind();

            QuestionSelected?.Invoke(this, EventArgs.Empty);
        }
예제 #2
0
 public void SelectQuestion_Executed(object arg)
 {
     QuestionSelected?.Invoke((QuestionInfoViewModel)arg);
 }