protected override void BuildDisplayShape(BuildDisplayContext context) { base.BuildDisplayShape(context); if (context.DisplayType == "Detail") { QuestionnairePart qp = context.ContentItem.As <QuestionnairePart>(); if (qp != null) { Int32 QuestionsSortedRandomlyNumber = qp.Settings.GetModel <QuestionnairesPartSettingVM>().QuestionsSortedRandomlyNumber; if (QuestionsSortedRandomlyNumber > 0) { qp.QuestionsToDisplay = Shuffle(qp.Questions.Where(x => x.Published).ToList().ConvertAll(x => (dynamic)x)).ConvertAll(x => (QuestionRecord)x).ToList().Take(QuestionsSortedRandomlyNumber).ToList(); } bool RandomResponse = qp.Settings.GetModel <QuestionnairesPartSettingVM>().RandomResponse; if (RandomResponse) { foreach (QuestionRecord qr in qp.Questions) { qr.Answers = Shuffle(qr.Answers.ToList().ConvertAll(x => (dynamic)x)).ConvertAll(x => (AnswerRecord)x).ToList(); } } } } }
protected void InitializeQuestionsToDisplay(QuestionnairePart part) { // Pre load some stuff in the QuestionsToDisplay property. This way, when we do _contentManager.Get(id) // of an item that has the QuestionnairePart, that property has a value already. We will want to set it // back to null when building an editor shape, because we edit the List of QuestionRecords // We are going to set the QuestionsToDisplay property to null in the QuestionnairesServices called in the // driver, because the BuildEditorShape handler is called after the Editor method from the driver. var qNumber = part.Settings .GetModel <QuestionnairesPartSettingVM>() .QuestionsSortedRandomlyNumber; if (qNumber > 0) { part.QuestionsToDisplay = Shuffle( part.Questions .Where(x => x.Published) .ToList() .ConvertAll(x => (dynamic)x)) .ConvertAll(x => (QuestionRecord)x) .ToList() .Take(qNumber) .ToList(); } if (part.Settings .GetModel <QuestionnairesPartSettingVM>() .RandomResponse) { foreach (var qr in part.Questions) { qr.Answers = Shuffle(qr.Answers.ToList().ConvertAll(x => (dynamic)x)) .ConvertAll(x => (AnswerRecord)x).ToList(); } } }
private void ShuffleQuestions(ContentItem ci, dynamic field) { ContentItem sampleContentItem = (ContentItem)field.ContentItems[0]; QuestionnairePart qp = sampleContentItem.As <QuestionnairePart>(); if (qp != null) { Int32 QuestionsSortedRandomlyNumber = ci.As <GamePart>().QuestionsSortedRandomlyNumber;// qp.Settings.GetModel<QuestionnairesPartSettingVM>().QuestionsSortedRandomlyNumber; if (QuestionsSortedRandomlyNumber > 0) { qp.QuestionsToDisplay = Shuffle(qp.Questions.Where(x => x.Published).ToList().ConvertAll(x => (dynamic)x)).ConvertAll(x => (QuestionRecord)x).ToList().Take(QuestionsSortedRandomlyNumber).ToList(); } bool RandomResponse = ci.As <GamePart>().RandomResponse;// qp.Settings.GetModel<QuestionnairesPartSettingVM>().RandomResponse; if (RandomResponse) { foreach (QuestionRecord qr in qp.Questions) { qr.Answers = Shuffle(qr.Answers.ToList().ConvertAll(x => (dynamic)x)).ConvertAll(x => (AnswerRecord)x).ToList(); } } } }