Beispiel #1
0
        public void DeleteQuiz(QuizData theQuiz)
        {
            if (DataReader != null)
            {
                DataReader.Close();
            }

            QuestionEntity quest = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                quest.DeleteQuestion(theQuiz.Questions[i]);
            }

            quest.Dispose();

            SQL = "DELETE `quizzes`, `rel_courses_quizzes` FROM `quizzes` INNER JOIN `rel_courses_quizzes` ON `quizzes`.`quiz_id` = `rel_courses_quizzes`.`quiz_id` WHERE `quizzes`.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
            {
                throw new Exception("Could not delete the Quiz from Database");
            }
        }
Beispiel #2
0
        public void UpdateQuiz(QuizData theQuiz)
        {
            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                QuestionData questionToSave;
                questionToSave = theQuiz.Questions[i];
                if (questionToSave.Id == 0)
                {
                    temp.CreateQuestion(questionToSave);
                    AddQuestion(theQuiz, questionToSave);
                }
                else
                {
                    temp.UpdateQuestion(questionToSave);
                }
            }


            temp.Dispose();

            SQL = "UPDATE `quizzes` q SET q.`name` = \"" + theQuiz.Name + "\", q.`open_date` = \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", q.`due_date` = \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\" WHERE q.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
            {
                throw new Exception("Unable to update the quiz on the database");
            }
        }
Beispiel #3
0
        /// <summary>
        /// validates data and if good saves it
        /// </summary>
        /// <param name="quiz">quiz to submit</param>
        /// <exception cref="Exception">data not correct.</exception>
        public static void SubmitQuiz(QuizData quiz)
        {
            QuestionEntity temp = new QuestionEntity();
            quiz.Questions.AddRange(temp.ReadQuestions(quiz));
            temp.Dispose();
            //Validate data
            if (quiz.Due < quiz.Open)
                throw new Exception("The due date must be after the open date.");

            if (quiz.Questions.Count == 0)
                throw new Exception("The quiz must contain at least one question.");

            // Validation for questions takes place when creating the individual questions

            //Now that we validated save the quiz
            SaveQuiz(quiz);
        }
Beispiel #4
0
        public void UpdateQuiz(QuizData theQuiz)
        {
            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                QuestionData questionToSave;
                questionToSave = theQuiz.Questions[i];
                if (questionToSave.Id == 0)
                {
                    temp.CreateQuestion(questionToSave);
                    AddQuestion(theQuiz, questionToSave);

                }
                else
                    temp.UpdateQuestion(questionToSave);

            }

            temp.Dispose();

            SQL = "UPDATE `quizzes` q SET q.`name` = \"" + theQuiz.Name + "\", q.`open_date` = \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", q.`due_date` = \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\" WHERE q.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to update the quiz on the database");
        }
Beispiel #5
0
        public void DeleteQuiz(QuizData theQuiz)
        {
            if (DataReader != null)
                DataReader.Close();

            QuestionEntity quest = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
                quest.DeleteQuestion(theQuiz.Questions[i]);

            quest.Dispose();

            SQL = "DELETE `quizzes`, `rel_courses_quizzes` FROM `quizzes` INNER JOIN `rel_courses_quizzes` ON `quizzes`.`quiz_id` = `rel_courses_quizzes`.`quiz_id` WHERE `quizzes`.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Could not delete the Quiz from Database");
        }