bool IRegisterDatabaseContext.InsertUser(UserDTO userDTO) { MySqlCommand storeData = new MySqlCommand("INSERT INTO `user`(`firstname`, `lastname`, `email`, `password`, `birth_day`) VALUES (@val1,@val2,@val3,@val4,@val5);"); storeData.Parameters.AddWithValue("@val1", userDTO.FirstName); storeData.Parameters.AddWithValue("@val2", userDTO.LastName); storeData.Parameters.AddWithValue("@val3", userDTO.Email); storeData.Parameters.AddWithValue("@val4", userDTO.Password); storeData.Parameters.AddWithValue("@val5", userDTO.BirthDay); return(DatabaseClass.StoreData(storeData, true)); }
public bool InsertToScoreboard(SubmitDTO submitDTO) { InsertQuestionList(submitDTO.QuestionList); MySqlCommand SelectQuestionIDCommand = new MySqlCommand("INSERT INTO `scoreboard` ( `user`, `category`, `difficulty`, `amount_of_questions`, `question_list`, `score`, `date`) VALUES(@val1,@val2,@val3,@val4,@val5,@val6, current_timestamp());"); SelectQuestionIDCommand.Parameters.AddWithValue("@val1", submitDTO.UniqueID); SelectQuestionIDCommand.Parameters.AddWithValue("@val2", submitDTO.Category); SelectQuestionIDCommand.Parameters.AddWithValue("@val3", submitDTO.Difficulty); SelectQuestionIDCommand.Parameters.AddWithValue("@val4", 10); SelectQuestionIDCommand.Parameters.AddWithValue("@val5", SelectQuestionListID()); SelectQuestionIDCommand.Parameters.AddWithValue("@val6", submitDTO.Score); return(DatabaseClass.StoreData(SelectQuestionIDCommand, true)); }
public bool InsertQuestionList(List <string> Question_List) { if (Question_List.Count() == 10) { MySqlCommand InsertQuestionListCommand = new MySqlCommand("INSERT INTO `question_list`(`1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`) VALUES (@val1,@val2,@val3,@val4,@val5,@val6,@val7,@val8,@val9,@val10)"); InsertQuestionListCommand.Parameters.AddWithValue("@val1", Question_List[0]); InsertQuestionListCommand.Parameters.AddWithValue("@val2", Question_List[1]); InsertQuestionListCommand.Parameters.AddWithValue("@val3", Question_List[2]); InsertQuestionListCommand.Parameters.AddWithValue("@val4", Question_List[3]); InsertQuestionListCommand.Parameters.AddWithValue("@val5", Question_List[4]); InsertQuestionListCommand.Parameters.AddWithValue("@val6", Question_List[5]); InsertQuestionListCommand.Parameters.AddWithValue("@val7", Question_List[6]); InsertQuestionListCommand.Parameters.AddWithValue("@val8", Question_List[7]); InsertQuestionListCommand.Parameters.AddWithValue("@val9", Question_List[8]); InsertQuestionListCommand.Parameters.AddWithValue("@val10", Question_List[9]); return(DatabaseClass.StoreData(InsertQuestionListCommand, true)); } return(false); }
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); }