Beispiel #1
0
        public List <CompletedQuestion> GetCompletedQuestion(CompletedQuiz cq, List <StoredQuizQuestions> SQS)
        {
            //Gets the individual scores for each person and their questions answered
            List <CompletedQuestion> CQ       = new List <CompletedQuestion>();
            CompletedQuestion        question = new CompletedQuestion();

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("Physicsdb")))
            {
                foreach (StoredQuizQuestions QuizQuestion in SQS)
                {
                    try
                    {
                        //The program will try to retervie the completed question that contains their studentID and QuestionsID
                        question = connection.QuerySingle <CompletedQuestion>("exec dbo.CompletedQuestion_GetQuestion @questionId, @studentId", new { questionId = QuizQuestion.QuestionId, studentId = cq.StudentId });
                    }
                    catch (Exception)
                    {
                        //If the program cannot reterive the completed question it will create a new one
                        question = connection.QuerySingle <CompletedQuestion>(" dbo.CompletedQuestion_Create @questionId, @studentId", new { questionId = QuizQuestion.QuestionId, studentId = cq.StudentId });
                    }
                    CQ.Add(question);
                }
            }
            return(CQ);
        }
Beispiel #2
0
 public CompletedQuiz CreateCompletedQuiz(CompletedQuiz quiz)
 {
     //If a student has never ran a quiz before the program must create the records in the table of CompletedQuiz in order to store their progress.
     //It does this by creating a composite key consisting of StudentID and the quiz ID
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("Physicsdb")))
     {
         var Quiz = connection.QuerySingle <CompletedQuiz>("exec dbo.CompletedQuiz_CreateQuiz @quizId, @studentId, @length", new { quizId = quiz.Id, studentId = quiz.StudentId, length = quiz.Length });
         return(Quiz);
     }
 }