コード例 #1
0
 public static AnswerResult AddPollAnswer(DataObjectPollQuestion pollQuestion, List <int> questionPosition)
 {
     return(AddPollAnswer(pollQuestion, questionPosition, null, null));
 }
コード例 #2
0
        public static AnswerResult AddPollAnswer(DataObjectPollQuestion pollQuestion, List <int> questionPosition, string comment, string nickName)
        {
            AnswerResult retVal = AnswerResult.AlreadyVoted;

            if (pollQuestion != null && pollQuestion.IsReadyForVoting)
            {
                if (pollQuestion.UserDataContext.IsAuthenticated || pollQuestion.AnonymousAllowed)
                {
                    if (pollQuestion.HasVoted)
                    {
                        return(retVal);
                    }

                    int rightAnswers = pollQuestion.CountRightAnswer();
                    int rightAnswer  = 0;

                    int max = questionPosition.Count;
                    if (pollQuestion.PollType == QuestionPollType.SingleAnswer)
                    {
                        max = 1;
                    }

                    for (int x = 0; x < max; x++)
                    {
                        DataObjectPollAnswer pollAnswer = new DataObjectPollAnswer(pollQuestion.UserDataContext);
                        pollAnswer.CommunityID = pollQuestion.CommunityID;
                        pollAnswer.Title       = pollQuestion.Answers[questionPosition[x]].Answer.CropString(100);
                        if (!string.IsNullOrEmpty(nickName))
                        {
                            pollAnswer.nickname = nickName.CropString(256);
                        }

                        pollAnswer.Position = questionPosition[x];
                        pollAnswer.Answer   = 1;

                        pollAnswer.Insert(pollQuestion.ObjectID.Value, pollQuestion.ObjectType);

                        if (pollQuestion.UserDataContext.IsAuthenticated)
                        {
                            pollQuestion.Answers[questionPosition[x]].Registerd += pollAnswer.Answer;
                        }
                        else
                        {
                            pollQuestion.Answers[questionPosition[x]].Anonnymous += pollAnswer.Answer;
                        }

                        if (pollQuestion.Answers[questionPosition[x]].IsRight)
                        {
                            rightAnswer++;
                        }
                    }

                    pollQuestion.UpdateAnswers(pollQuestion.Answers);
                    pollQuestion.UpdateBackground();

                    if (rightAnswer == rightAnswers && rightAnswer == max)
                    {
                        retVal = AnswerResult.Right;
                    }
                    else if (rightAnswer == rightAnswers && rightAnswer != max)
                    {
                        retVal = AnswerResult.Partially;
                    }
                    else if (rightAnswer < rightAnswers && rightAnswer > 0)
                    {
                        retVal = AnswerResult.Partially;
                    }
                    else
                    {
                        retVal = AnswerResult.False;
                    }
                }
            }
            return(retVal);
        }
コード例 #3
0
 public static AnswerResult AddPollAnswer(UserDataContext udc, DataObjectPollQuestion pollQuestion, List <int> questionPosition)
 {
     return(AddPollAnswer(udc, pollQuestion, questionPosition, null, null));
 }