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"); } }
public void CreateQuiz(QuizData theQuiz) { theQuiz.id = NextId; if (DataReader != null) { DataReader.Close(); } SQL = "INSERT INTO `quizzes` (`quiz_id`, `name`, `open_date`, `due_date`) VALUES " + "(\"" + theQuiz.id + "\", \"" + theQuiz.Name + "\", \"" + theQuiz.Added.ToString("yyyy-MM-dd") + "\", \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\");"; InitializeCommand(); OpenConnection(); int result = ExecuteStoredProcedure(); if (result == 0) { throw new Exception("Could Not add the quiz to the database"); } QuestionEntity temp = new QuestionEntity(); for (int i = 0; i < theQuiz.questions.Count; i++) { temp.CreateQuestion(theQuiz.questions[i]); if (DataReader != null) { DataReader.Close(); } SQL = "INSERT INTO `rel_quizzes_questions` (`quiz_id`, `question_id`) VALUES (\"" + theQuiz.id + "\", \"" + theQuiz.questions[i].id + "\");"; InitializeCommand(); OpenConnection(); result = ExecuteStoredProcedure(); if (result == 0) { throw new Exception("Cannot associate this question with this quiz"); } } CloseConnection(); }
public void CreateQuiz(QuizData theQuiz) { theQuiz.Id = NextId; if (DataReader != null) DataReader.Close(); SQL = "INSERT INTO `quizzes` (`quiz_id`, `name`, `open_date`, `due_date`) VALUES " + "(\"" + theQuiz.Id + "\", \"" + theQuiz.Name + "\", \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\");"; InitializeCommand(); int result = ExecuteStoredProcedure(); if (result == 0) throw new Exception("Could Not add the quiz to the database"); QuestionEntity temp = new QuestionEntity(); for (int i = 0; i < theQuiz.Questions.Count; i++) { temp.CreateQuestion(theQuiz.Questions[i]); if (DataReader != null) DataReader.Close(); SQL = "INSERT INTO `rel_quizzes_questions` (`quiz_id`, `question_id`) VALUES (\"" + theQuiz.Id + "\", \"" + theQuiz.Questions[i].Id + "\");"; InitializeCommand(); result = ExecuteStoredProcedure(); if (result == 0) throw new Exception("Cannot associate this question with this quiz"); } }
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"); }