Пример #1
0
 public Question(string content, string A, string B, string C, string D, AnswerEnum answer)
 {
     this.content = content.Trim();
     this.answerA = A.Trim();
     this.answerB = B.Trim();
     this.answerC = C.Trim();
     this.answerD = D.Trim();
     this.answer  = answer;
 }
Пример #2
0
 public void SetAnswer(AnswerEnum answerValue)
 {
     Answer.Answer_Text = answerValue.GetStringAttribute();
     QuestionAnswer     = answerValue;
     if (answerValue != AnswerEnum.UNANSWERED && this.Parameters != null)
     {
         var nonExplicits = this.Parameters.Where(s => !s.IsExplicitlySet).ToList();
         foreach (var parameter in nonExplicits)
         {
             parameter.IsExplicitlySet = true;
         }
     }
 }
Пример #3
0
        public ActionResult AnswerQuestion(int questionId, string content = "", AnswerEnum type = AnswerEnum.Answer)
        {
            Answer answer = new Answer();

            answer.Content        = content;
            answer.UserId         = Int32.Parse(User.Identity.GetUserId());
            answer.CreatedDate    = DateTime.Now;
            answer.LastEditedDate = answer.CreatedDate;
            answer.QuestionId     = questionId;
            answer.Type           = type;
            answer.VoteDown       = 0;
            answer.VoteUp         = 0;
            answer.Accepted       = false;
            answer.Status         = PostStatusEnum.Active;

            qService.AnswerQuestion(answer);

            //new Thread(() =>
            //{
            Question question = qService.GetQuestion(questionId);

            if (question.UserId != _currentUserId)
            {
                Notification notification = new Notification();
                notification.AuthorId    = _currentUserId;
                notification.CreatedDate = DateTime.Now;
                notification.Content     = question.Title;
                notification.Seen        = false;
                notification.Type        = answer.Type == AnswerEnum.Answer ? NotificationSettingEnum.UserAnswerQuestion : NotificationSettingEnum.UserHintQuestion;
                notification.UserId      = question.UserId;
                notification.Link        = Url.Action("Detail", "Question", new { id = question.Id });
                cService.AddNotification(notification);

                using (RealTimeService rService = new RealTimeService(new CPMathHubModelContainer(), notification.UserId))
                {
                    IEnumerable <string> connectionIds = RealTimeHub.Connections.GetConnections(notification.UserId);
                    foreach (string conId in connectionIds)
                    {
                        _hub.Clients.Client(conId).notifyNewActivity(rService.CountNewActivityNotification());
                    }
                }
                //}
                //).Start();
            }
            return(RedirectToAction("Detail", new { id = questionId }));
        }
        private async Task AddOrUpdateEnumAnswer(int eventId, Dictionary <int, AnswerEnum> answerEnums, QuestionTextModel question, string answer)
        {
            if (!answerEnums.ContainsKey(question.Id))
            {
                var answerEnum = new AnswerEnum
                {
                    QuestionId         = question.Id,
                    EventId            = eventId,
                    QuestionEnumAnswer = Enum.Parse <Answer>(answer)
                };

                _context.Add(answerEnum);
                await _context.SaveChangesAsync();
            }
            else
            {
                var answerEnum = answerEnums[question.Id];
                answerEnum.QuestionEnumAnswer = Enum.Parse <Answer>(answer);
                _context.Update(answerEnum);
                await _context.SaveChangesAsync();
            }
        }
        public IActionResult Solve(int id, AnswerEnum answer)
        {
            int questionIndex = (int)HttpContext.Session.GetInt32("QuestionIndex");
            //int questionIndex = (int)TempData["QuestionIndex"];

            // get quiz obj by id from URL and fill it with correcponding questions
            var quiz = _context.Quizzes.Find(id);

            foreach (var question in _context.Questions.Where(q => q.QuizID == id))
            {
                quiz.Questions.Add(question);
            }

            // pass questions to a list
            var questionsList = quiz.Questions.ToList();

            // check answers and set result in tempdata
            if (questionsList[questionIndex].CorrectAnswer == answer)
            {
                HttpContext.Session.SetInt32(questionIndex.ToString(), 1);
                //TempData[questionIndex.ToString()] = 1;
            }
            else
            {
                HttpContext.Session.SetInt32(questionIndex.ToString(), 0);
                //TempData[questionIndex.ToString()] = 0;
            }

            // check for last question and then set number of questions and redirect to summary
            if (questionsList.Count == questionIndex + 1)
            {
                HttpContext.Session.SetInt32("NumberOfQuestions", questionsList.Count);
                //TempData["NumberOfQuestions"] = questionsList.Count;
                return(RedirectToAction("Summary"));
            }

            // redirect to newxt question
            return(RedirectToAction("Solve", "Quizzes", new { questionIndex = questionIndex + 1 }));
        }
Пример #6
0
        public List <Answer> GetAnswers(int questionId, AnswerEnum type)
        {
            List <Answer> answers = new List <Answer>();

            switch (type)
            {
            case AnswerEnum.Answer:
                answers = _dal.Repository <Answer>().Get(
                    ExpressionHelper.QuestionHelper.AnswerOfQuestion(questionId),
                    ExpressionHelper.QuestionHelper.OrderUsefulAnswer(),
                    "Author",
                    0,
                    0
                    ).ToList();
                break;

            case AnswerEnum.Hint:
                answers = _dal.Repository <Answer>().Get(
                    ExpressionHelper.QuestionHelper.HintOfQuestion(questionId),
                    ExpressionHelper.QuestionHelper.OrderUsefulAnswer(),
                    "Author",
                    0,
                    0
                    ).ToList();
                break;

            default:
                answers = _dal.Repository <Answer>().Get(
                    (a => a.QuestionId == questionId),
                    ExpressionHelper.QuestionHelper.OrderUsefulAnswer(),
                    "Author",
                    0,
                    0
                    ).ToList();
                break;
            }
            IncludeCommentForAnswers(answers);
            return(answers);
        }
Пример #7
0
 public void SelectAnswer(AnswerEnum selectedAnswer) => selectedAnswers[currentQuestionNumber] = selectedAnswer;
Пример #8
0
 internal void SetAnswer(AnswerEnum answer)
 {
     QuestionAnswer = answer;
 }