public Poll GetPollContainingQuestion(Question question) { var poll = (from item in session.Query<Poll>() where item.questions.Contains(question) select item).FirstOrDefault(); return poll; }
public static Boolean CanEditQuestion(User user, Poll poll, Question question) { if (poll.isTestPoll) { return true; } if (question == null) { if (user.Roles.Contains(new Role("Poll Master"))) { return true; } else { return false; } } foreach (var managedPoll in user.ManagedPolls) { if (managedPoll.questions.Contains(question)) { return true; } } foreach (var createdPoll in user.CreatedPolls) { if (createdPoll.questions.Contains(question)) { return true; } } if (poll.pollMasters.Contains(user)) { return true; } return false; }
public QuestionAndPoll(Question question, Poll poll) { this.question = question; this.poll = poll; }
public IDictionary<String, int> QuestionResult(Question question) { // Create a dictionary to store that question's responses IDictionary<String, int> responses = new Dictionary<String, int>(); if (question.type == QuestionType.Numeric) { // If a numeric question NumericQuestion numericQuestion = questionRepository.GetQuestionByID<NumericQuestion>(question.questionID); int numCorrect = 0; int numIncorrect = 0; foreach (var response in numericQuestion.responses) { // Check if the answer is correct if ((Convert.ToInt32(response.response) < numericQuestion.lessThan) && (Convert.ToInt32(response.response) > numericQuestion.greaterThan)) { numCorrect += response.participant.votingWeight; } else { numIncorrect += response.participant.votingWeight; } } if (numericQuestion.lessThan-numericQuestion.greaterThan==2) responses.Add("Correct [" + (numericQuestion.greaterThan+1) + "]", numCorrect); else responses.Add("Correct [" + numericQuestion.greaterThan.ToString() + " - " + numericQuestion.lessThan.ToString() + "]", numCorrect); responses.Add("Incorrect", numIncorrect); } else if (question.type == QuestionType.Alphanumeric) { // If an alphanumeric question AlphanumericQuestion alphaQuestion = questionRepository.GetQuestionByID<AlphanumericQuestion>(question.questionID); // Get correct responses int numCorrect = 0; int numIncorrect = 0; int total = 0; foreach (var response in alphaQuestion.responses) { foreach (var answer in alphaQuestion.answers) { if (response.response.Equals(answer.answer)) { numCorrect += response.participant.votingWeight; } } total += response.participant.votingWeight; } // Build a string of correct answers String correctAnswers = ""; foreach (var answer in alphaQuestion.answers) { if (correctAnswers != "") { correctAnswers += ", "; } correctAnswers += answer.answer; } responses.Add("Correct [" + correctAnswers + "]", numCorrect); numIncorrect = total - numCorrect; responses.Add("Incorrect", numIncorrect); } else if (question.type == QuestionType.Ranking) { RankingQuestion rankingQuestion = questionRepository.GetQuestionByID<RankingQuestion>(question.questionID); foreach (var option in rankingQuestion.options) { int a = (from o in option.responses select o.participant.votingWeight*rankingQuestion.rankValues.ElementAt(o.rank-1).value).Sum(); responses.Add(option.answer, a); } } else { // IF MCQ MultipleChoiceQuestion multipleQuestion = questionRepository.GetQuestionByID<MultipleChoiceQuestion>(question.questionID); foreach (var option in multipleQuestion.options) { int a = (from o in option.responses select o.participant.votingWeight).Sum(); responses.Add(option.answer, a); } } return responses; }