示例#1
0
        public Grade Grade(OnlineExam toBeGradedExam)
        {
            UnitOfWork      work        = new UnitOfWork();
            Question        thE         = toBeGradedExam.Questions[0];
            List <Question> theQuestion = work.QuestionRepository.Get(a => a.QuestionID == thE.QuestionID).ToList();
            Question        theQuestio  = theQuestion[0];


            List <OnlineExam> theExam       = work.OnlineExamRepository.Get(a => a.OnlineExamID == theQuestio.OnlineExamID).ToList();
            OnlineExam        persistedExam = new OnlineExam();

            persistedExam = theExam[0];
            IList <Question> theQs = new ExamService().GetQuestions(theExam[0]);

            persistedExam.AddQuestion(theQs);

            var grade = new Grade()
            {
                Exam = persistedExam
            };

            foreach (var question in toBeGradedExam.Questions)
            {
                var persistedQuestion = (from q in persistedExam.Questions
                                         where q.QuestionID == question.QuestionID
                                         select q).SingleOrDefault();

                if (persistedQuestion != null)
                {
                    grade.TotalPoints += persistedQuestion.Point;
                    foreach (var choice in question.Choices)
                    {
                        var persistedChoice = (from c in persistedQuestion.Choices
                                               where c.ChoiceID == choice.ChoiceID
                                               select c).SingleOrDefault();

                        // sets the user choice in the actual exam fetched from database!
                        persistedChoice.IsSelected = true;

                        // grade.TotalPoints += persistedQuestion.Point;
                        if (persistedChoice.IsAnswer)
                        {
                            grade.Score += persistedQuestion.Point;
                        }
                    }
                }
            }

            return(grade);
        }
示例#2
0
        public Grade Grade(OnlineExam toBeGradedExam)
        {
            UnitOfWork work = new UnitOfWork();
            Question thE = toBeGradedExam.Questions[0];
            List<Question> theQuestion = work.QuestionRepository.Get(a => a.QuestionID == thE.QuestionID).ToList();
            Question theQuestio = theQuestion[0];

            List<OnlineExam> theExam = work.OnlineExamRepository.Get(a => a.OnlineExamID == theQuestio.OnlineExamID).ToList();
            OnlineExam persistedExam = new OnlineExam();
            persistedExam = theExam[0];
            IList<Question> theQs = new ExamService().GetQuestions(theExam[0]);
            persistedExam.AddQuestion(theQs);

            var grade = new Grade() { Exam = persistedExam };

            foreach (var question in toBeGradedExam.Questions)
            {
                var persistedQuestion = (from q in persistedExam.Questions
                                         where q.QuestionID == question.QuestionID
                                         select q).SingleOrDefault();

                if (persistedQuestion != null)
                {
                    grade.TotalPoints += persistedQuestion.Point;
                    foreach (var choice in question.Choices)
                    {
                        var persistedChoice = (from c in persistedQuestion.Choices
                                               where c.ChoiceID == choice.ChoiceID
                                               select c).SingleOrDefault();

                        // sets the user choice in the actual exam fetched from database!
                        persistedChoice.IsSelected = true;

                       // grade.TotalPoints += persistedQuestion.Point;
                        if (persistedChoice.IsAnswer)
                        {
                            grade.Score += persistedQuestion.Point;
                        }
                    }
                }
            }

            return grade;
        }