Exemple #1
0
        public QuestionDTO SelectQuestionDatabase(string difficulty, string category)
        {
            QuestionDTO questionDTO      = new QuestionDTO {
            };
            MySqlCommand getQuestionData = new MySqlCommand("SELECT * FROM `question` WHERE `id`= @val1");

            getQuestionData.Parameters.AddWithValue("@val1", SelectQuestionID(difficulty, category));
            List <string> results = DatabaseClass.GetData(getQuestionData, true);

            questionDTO.Question = results[2];
            List <string> incorrect_Answers = new List <string> {
                results[3], results[4], results[5]
            };

            questionDTO.IncorrectAnswers = incorrect_Answers;
            questionDTO.CorrectAnswer    = results[6];
            return(questionDTO);
        }
Exemple #2
0
        public bool InsertQuestionDatabase(QuestionDTO questionDTO, string difficulty, string category)
        {
            MySqlCommand checkQuestion = new MySqlCommand("SELECT * FROM question WHERE `question` = @val1");

            checkQuestion.Parameters.AddWithValue("@val1", questionDTO.Question);
            List <string> results = DatabaseClass.GetData(checkQuestion, true);

            if (results.Count == 0)
            {
                MySqlCommand insertQuestion = new MySqlCommand("INSERT INTO `question`(`question`, `category`,`incorrect_answer1`, `incorrect_answer2`, `incorrect_answer3`, `correct_answer`,`difficulty`) VALUES (@val1,@val2,@val3,@val4,@val5,@val6,@val7)");
                insertQuestion.Parameters.AddWithValue("@val1", questionDTO.Question);
                insertQuestion.Parameters.AddWithValue("@val2", category);
                insertQuestion.Parameters.AddWithValue("@val3", questionDTO.IncorrectAnswers[0]);
                insertQuestion.Parameters.AddWithValue("@val4", questionDTO.IncorrectAnswers[1]);
                insertQuestion.Parameters.AddWithValue("@val5", questionDTO.IncorrectAnswers[2]);
                insertQuestion.Parameters.AddWithValue("@val6", questionDTO.CorrectAnswer);
                insertQuestion.Parameters.AddWithValue("@val7", difficulty);
                if (DatabaseClass.StoreData(insertQuestion, true) != true)
                {
                    return(false);
                }
            }
            return(true);
        }