예제 #1
0
        public ScoreCard GetScore(int testId, int studentId)
        {
            // calculating score and max marks
            var responses = _responseRepo.GetResponsesByStudentIdAndTestId(testId, studentId);
            var testQues  = _testQuesRepo.GetByTestId(testId);
            var questions = new List <Question>();
            int maxMarks  = 0;

            foreach (var item in testQues)
            {
                var ques = _questionRepo.GetById(item.QuestionId);
                maxMarks = maxMarks + ques.Marks;
            }

            int marks = 0;

            foreach (var item in responses)
            {
                var ques = _questionRepo.GetById(item.QuestionId);
                if (ques.Answer == item.Answer)
                {
                    marks = marks + ques.Marks;
                }
            }
            //calculating percentage
            var per       = (double)marks / (double)maxMarks * 100;
            var scoreCard = new ScoreCard()
            {
                MarksScored = marks,
                MaxMarks    = maxMarks,
                Percentage  = per
            };

            return(scoreCard);
        }
예제 #2
0
        /// <summary>
        /// get question for giving test
        /// </summary>
        /// <param name="testId"></param>
        /// <param name="no"></param>
        /// <returns>question</returns>
        public QuesGiveTestViewModel GetQuestionForGivingTest(int testId, int no)
        {
            no = --no;
            //get current question for student to attempt
            var testQues    = _testQuesRepo.GetByTestId(testId).Skip(no).Take(1).First();
            var question    = _questionRepo.GetById(testQues.QuestionId);
            var quesForTest = new QuesGiveTestViewModel()
            {
                Id        = question.Id,
                OptionA   = question.OptionA,
                OptionB   = question.OptionB,
                OptionC   = question.OptionC,
                OptionD   = question.OptionD,
                QuesSting = question.QuesString,
                Time      = question.Time,
                Marks     = question.Marks,
                TestId    = testId
            };

            return(quesForTest);
        }
예제 #3
0
 public List <TestQues> GetTestQuesByTestId(int testId)
 {
     return(_testQuesRepo.GetByTestId(testId));
 }