Ejemplo n.º 1
0
        public void CalculatePoints(int id)
        {
            StudentExam studentExam = _studentExamManager.Get(id);
            double      points      = 0;

            foreach (StudentExamAnswer s in studentExam.StudentExamAnswers)
            {
                points += s.CalculatePoints();
            }
            studentExam.Points = points;
            _studentExamManager.Update(studentExam);
        }
Ejemplo n.º 2
0
        // GET: ExamQuestions
        // Listing all the Questions related to a studentExam and providing the possibility to answer
        public IActionResult Index(int?pageNumber)
        {
            try
            {
                int?studentExamId = (int)TempData["studentExamId"];

                StudentExam studentExam = _studentExamManager.Get(studentExamId);
                List <ExamQuestionViewModel> examQuestionViewModels = new List <ExamQuestionViewModel>();
                int i = 0;
                foreach (Question q in studentExam.Exam.ExamQuestions)
                {
                    i++;
                    ExamQuestionViewModel examQuestionViewModel = NewExamQuestionViewModel(studentExam, q, i);

                    foreach (StudentExamAnswer a in examQuestionViewModel.StudentExam.StudentExamAnswers)
                    {
                        //Setting Question answered true if has exists
                        if (a.Question.Id == q.Id)
                        {
                            examQuestionViewModel.Answered = true;
                            break;
                        }
                        else
                        {
                            examQuestionViewModel.Answered = false;
                        }
                    }


                    examQuestionViewModels.Add(examQuestionViewModel);
                }

                TempData["studentExamId"] = studentExam.Id;
                int pageSize = 8;
                return(View(PaginatedList <ExamQuestionViewModel> .Create(examQuestionViewModels, pageNumber ?? 1, pageSize)));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }