Exemple #1
0
        public ActionResult AnswerQuestion(int questionId, int[] orders)
        {
            var ip           = Request.UserHostAddress;
            var userAnswered = _pollRepository.CheckUserAnswered(questionId, ip);
            var question     = _pollRepository.QuestionAnswers(questionId);

            if (!userAnswered)
            {
                foreach (var order in orders)
                {
                    var userAnswer = _pollRepository.FindUserAnswer(questionId, order, ip);
                    if (userAnswer == null)
                    {
                        userAnswer = new PollUserAnswer
                        {
                            IP         = ip,
                            QuestionId = questionId,
                            AnswerId   = order
                        };
                        _pollRepository.InsertUserAnswer(userAnswer);
                    }
                }
                _pollRepository.Save();
                if (question.Published)
                {
                    return(Result(questionId));
                }
                else
                {
                    return(Content("<b>Cảm ơn bãn đã bình chọn !</b>"));
                }
            }
            else
            if (question.Published)
            {
                return(Result(questionId));
            }
            else
            {
                return(Content("<b>Cảm ơn bãn đã bình chọn !</b>"));
            }
        }