示例#1
0
        public void SandboxTest()
        {
            var context = new AppDbContext();

            var c1 = new Choice { Id = 1 };
            var c3 = new Choice { Id = 3 };

            var freeAnswer = new FreeTextAnswer { Comment = "my comments", QuestionId = 2 };

            var multipleAns = new MultipleChoicesAnswer
            {
                QuestionId = 1,
                SelectedChoices = new List<Choice> { c1, c3 }
            };

            var answer = new PollAnswer
            {
                AnswerDate = DateTime.Now,
                PollId = 1,
                QuestionAnswers = new List<QuestionAnswer> { freeAnswer, multipleAns }
            };

            context.PollAnswers.AddOrUpdate(answer);
            context.SaveChanges();
        }
        public ActionResult FinishAnswerMultipleChoicesQuestion(MultipleChoicesQuestion multipleChoicesQuestion)
        {
            var questionAnswer = new MultipleChoicesAnswer
            {
                SelectedChoices = new List<Choice>(multipleChoicesQuestion.Choices.Where(c => c.Selected)),
                QuestionId = multipleChoicesQuestion.Id
            };

            var pollAnswer = (PollAnswer)this.Session[PollAnswerKey];

            pollAnswer.QuestionAnswers.Add(questionAnswer);

            return this.RedirectToAction("AnswerQuestion");
        }