コード例 #1
0
        public ActionResult Fill(IList<FillQuestionsViewModel> questions)
        {
            if (!ModelState.IsValid)
            {
                return this.View(questions);
            }

            var participant = this.participant.GetParticipantByRateSystemIdAndUserId(questions[0].RateSystemId, User.Identity.GetUserId());

            foreach (var question in questions)
            {
                var currentAnswer = new ParticipantAnswer();

                if (question.HasMultipleAnswers)
                {
                    bool isNotChecked = question.QuestionAnswers.All(x => x.IsChecked == false);

                    if (isNotChecked)
                    {
                        this.ModelState.AddModelError(question.Id.ToString(), "Моля изберете най-малко един отговор!");
                        return this.View(questions);
                    }

                    foreach (var answer in question.QuestionAnswers)
                    {
                        if (answer.IsChecked)
                        {
                            currentAnswer.QuestionAnswerId = answer.Id;
                            currentAnswer.ParticipantId = participant.Id.ToString();

                            this.participantAnswers.Add(currentAnswer);
                            this.participantAnswers.SaveChanges();
                        }
                    }
                }
                else
                {
                    if (question.RadioGroupAnswer == null)
                    {
                        this.ModelState.AddModelError(question.Id.ToString(), "Моля изберете отговор!");
                        return this.View(questions);
                    }

                    currentAnswer.QuestionAnswerId = int.Parse(question.RadioGroupAnswer);
                    currentAnswer.ParticipantId = participant.Id.ToString();

                    this.participantAnswers.Add(currentAnswer);
                    this.participantAnswers.SaveChanges();
                }
            }

            participant.IsVoted = true;
            this.participant.Update(participant);
            this.participant.SaveChanges();

            this.AddNotification("Благодаря Ви, че гласувахте! Вашият глас е важен за мен.", NotificationType.SUCCESS);

            return this.RedirectToAction<HomeController>(c => c.Index());
        }
コード例 #2
0
 public void Add(ParticipantAnswer userAnswers)
 {
     this.userAnswers.Add(userAnswers);
 }