Esempio n. 1
0
        public QuizSolution GetQuizSolution(int qId, int sId)
        {
            VCDataModelContainer data = new VCDataModelContainer();
            int count = (from x in data.QuizSolutions
                         where x.StudentId == sId && x.QuizId == qId
                         select x).Count();

            if (count != 0)
            {
                QuizSolution qs = (from x in data.QuizSolutions
                                   where x.StudentId == sId && x.QuizId == qId
                                   select x).First();
                return(qs);
            }
            return(null);
        }
Esempio n. 2
0
 public void SaveQuizSolution(int quizId, int studentId, List <QuizQuestionSolution> solutions)
 {
     if (!DoesSolutionExist(quizId, studentId))
     {
         using (VCDataModelContainer data = new VCDataModelContainer())
         {
             int correct = 0, attempted = 0, marks = 0;
             for (int i = 0; i < solutions.Count; i++)
             {
                 QuizQuestion ques = data.QuizQuestions.Find(solutions[i].QuizQuestionId);
                 if (solutions[i].SelectedOption != 0)
                 {
                     attempted++;
                 }
                 solutions[i].IsCorrect = (ques.CorrectOption == solutions[i].SelectedOption);
                 if (solutions[i].IsCorrect)
                 {
                     correct++;
                     marks += ques.Marks;
                 }
             }
             QuizSolution solution = new QuizSolution();
             solution.StudentId = studentId;
             solution.QuizId    = quizId;
             solution.Correct   = correct;
             solution.Attempted = attempted;
             solution.Marks     = marks;
             data.QuizSolutions.Add(solution);
             data.SaveChanges();
             foreach (var s in solutions)
             {
                 solution.QuestionSolutions.Add(s);
             }
             data.SaveChanges();
         }
     }
 }