public ActionResult Edit(int id)
 {
     return(View(new EditQuestionModel
     {
         Question = questionFacade.GetQuestionById(id)
     }));
 }
示例#2
0
        public ActionResult TakeTest(int id, TestActiveModel testActive)
        {
            var tmp = testActive.Answers
                      .ToDictionary(checkboxModel => checkboxModel.Id, checkboxModel => checkboxModel.Selected);
            var str = new StringBuilder();

            double respts = 0;

            foreach (var questionDto in testActive.Questions)
            {
                var correctResult = 0;
                var correct       = 0;
                var wrong         = 0;
                var question      = questionFacade.GetQuestionById(questionDto.Id);

                foreach (var answerDto in question.Answers)
                {
                    if (answerDto.Correct && tmp.FirstOrDefault(s => s.Key == answerDto.Id).Value == answerDto.Correct)
                    {
                        correctResult++;
                    }
                    else if (!answerDto.Correct && tmp.FirstOrDefault(s => s.Key == answerDto.Id).Value)
                    {
                        wrong++;
                    }
                    if (answerDto.Correct)
                    {
                        correct++;
                    }
                }
                if (correct == 0)
                {
                    continue;
                }
                var count = (double)(correctResult - wrong) / correct;
                if (count < 0)
                {
                    count = 0;
                }
                count *= question.Points;


                respts += (Math.Round((double)(count * 4), MidpointRounding.ToEven) / 4);
            }

            foreach (var b in tmp)
            {
                str.Append(b.Key + "," + b.Value + ";");
            }

            resultFacade.CreateResult(new ResultDTO {
                TestTemplateId   = id,
                UserId           = Convert.ToInt32(User.Identity.GetUserId()),
                ResultString     = str.ToString(),
                ResultPoints     = respts,
                TestTemplateName = testActive.Name,
                Time             = DateTime.Now
            });



            return(RedirectToAction("Index"));
        }