Exemple #1
0
        public QuizSolution SaveSolution(SolutionForEvaluationModel quizSolution, string userId)
        {
            var quiz = this.quizzes.GetById(quizSolution.ForQuizId);

            if (quizSolution.SelectedAnswerIds.Count != quiz.NumberOfQuestions &&
                quizSolution.SelectedAnswerIds.Count != quiz.Questions.Count)
            {
                throw new QuizEvaluationException("Invalid Solution: Questions count mismatch");
            }

            List <Answer> selectedAnswers = this.ExtractSelectedAnswers(quiz, quizSolution);

            var newSolution = new QuizSolution
            {
                ByUserId        = userId,
                ForQuiz         = quiz,
                SelectedAnswers = selectedAnswers
            };

            try
            {
                this.solutions.Add(newSolution);
                this.solutions.Save();
            }
            catch (Exception ex)
            {
                // Todo: Implement concrete exception cases
                throw new QuizEvaluationException("Something went wrong while saving your solution.", ex);
            }

            return(newSolution);
        }
        public QuizEvaluationResult EvaluateSolution(QuizSolution quizSolution)
        {
            var result = new QuizEvaluationResult
            {
                ForQuizId = quizSolution.ForQuizId,
                Title = quizSolution.ForQuiz.Title,
                CorrectlyAnswered = new List<QuestionResultModel>(),
                IncorrectlyAnswered = new List<QuestionResultModel>()
            };

            foreach (Answer answer in quizSolution.SelectedAnswers)
            {
                var questionResult = new QuestionResultModel
                {
                    Question = answer.ForQuestion.Title,
                    IsCorrect = answer.IsCorrect,
                    ResultDescription = answer.ForQuestion.ResultDescription,
                    SelectedAnswer = answer.Text,
                    CorrectAnswer = answer.ForQuestion
                        .Answers.First(a => a.IsCorrect).Text
                };

                if (answer.IsCorrect)
                {
                    result.CorrectlyAnswered.Add(questionResult);
                }
                else
                {
                    result.IncorrectlyAnswered.Add(questionResult);
                }
            }

            return result;
        }
Exemple #3
0
        public QuizEvaluationResult EvaluateSolution(QuizSolution quizSolution)
        {
            var result = new QuizEvaluationResult
            {
                ForQuizId           = quizSolution.ForQuizId,
                Title               = quizSolution.ForQuiz.Title,
                CorrectlyAnswered   = new List <QuestionResultModel>(),
                IncorrectlyAnswered = new List <QuestionResultModel>()
            };

            foreach (Answer answer in quizSolution.SelectedAnswers)
            {
                var questionResult = new QuestionResultModel
                {
                    Question          = answer.ForQuestion.Title,
                    IsCorrect         = answer.IsCorrect,
                    ResultDescription = answer.ForQuestion.ResultDescription,
                    SelectedAnswer    = answer.Text,
                    CorrectAnswer     = answer.ForQuestion
                                        .Answers.First(a => a.IsCorrect).Text
                };

                if (answer.IsCorrect)
                {
                    result.CorrectlyAnswered.Add(questionResult);
                }
                else
                {
                    result.IncorrectlyAnswered.Add(questionResult);
                }
            }

            return(result);
        }
Exemple #4
0
        public IQuizEvaluationResult Evaluate(QuizSolution solution)
        {
            var result = this.CreateEvaluation(solution);
            var answersByQuestionId = this.GetAnswersByQuestionId(solution);

            return(this.AddSelectedAnswers(answersByQuestionId, result));
        }
        public QuizSolution SaveSolution(SolutionForEvaluationModel quizSolution, string userId)
        {
            var quiz = this.quizzes.GetById(quizSolution.ForQuizId);

            if (quizSolution.SelectedAnswerIds.Count != quiz.NumberOfQuestions &&
                quizSolution.SelectedAnswerIds.Count != quiz.Questions.Count)
            {
                throw new QuizEvaluationException("Invalid Solution: Questions count mismatch");
            }

            List<Answer> selectedAnswers = this.ExtractSelectedAnswers(quiz, quizSolution);

            var newSolution = new QuizSolution
            {
                ByUserId = userId,
                ForQuiz = quiz,
                SelectedAnswers = selectedAnswers
            };

            try
            {
                this.solutions.Add(newSolution);
                this.solutions.Save();
            }
            catch (Exception ex)
            {
                // Todo: Implement concrete exception cases
                throw new QuizEvaluationException("Something went wrong while saving your solution.", ex);
            }

            return newSolution;
        }
Exemple #6
0
        private IQuizEvaluationResult CreateEvaluation(QuizSolution solution)
        {
            var result = this.mapper.Map <QuizEvaluationResult>(solution.ForQuiz);

            return(result);
        }
Exemple #7
0
        private IDictionary <int, Answer> GetAnswersByQuestionId(QuizSolution solution)
        {
            var result = solution.SelectedAnswers.ToDictionary(key => key.ForQuestionId);

            return(result);
        }
Exemple #8
0
        public ActionResult QuizResult(Parameter p)
        {
            if (p.Id == 0)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            LoginDetails loginDetails = (LoginDetails)Session["loginDetails"];

            if (loginDetails == null)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            int user = (int)Session["user"];

            if (user != 2)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            object o = Session["selectedClass"];

            if (o == null)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            int    id     = (int)o;
            Course course = data.GetCourse(id);

            if (course == null)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            Quiz q = data.GetQuiz(p.Id);

            if (q == null)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            int count = (from x in course.Quizzes
                         where x.Id == q.Id
                         select x).Count();

            if (count == 0)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            Student s = data.GetStudent(loginDetails.Username);

            if (!data.DoesSolutionExist(q.Id, s.Id))
            {
                return(RedirectToAction("Quiz", new { Id = p.Id }));
            }

            QuizSolution qs = data.GetQuizSolution(q.Id, s.Id);

            if (qs == null)
            {
                return(RedirectToAction("PageNotFoundError", "Home"));
            }
            return(View(new StudentCourseViewModel {
                course = course, quiz = q, solution = qs, student = s
            }));
        }