Ejemplo n.º 1
0
        public int SelectQuestionIDAddToQuestionList(string question)
        {
            MySqlCommand Get_Question_ID = new MySqlCommand("SELECT * FROM question WHERE `question` = @val1");

            Get_Question_ID.Parameters.AddWithValue("@val1", question);
            return(Convert.ToInt32(DatabaseClass.GetData(Get_Question_ID, true)[0]));
        }
Ejemplo n.º 2
0
        public int SelectQuestionListID()
        {
            MySqlCommand  SelectQuestionIDCommand = new MySqlCommand("SELECT MAX(`id`) FROM `question_list` WHERE 1");
            List <string> results = DatabaseClass.GetData(SelectQuestionIDCommand);

            return(Convert.ToInt32(results[0]));
        }
Ejemplo n.º 3
0
        private static string GetNameFromUniqueID(string user_ID)
        {
            MySqlCommand GetFirstNameCommand = new MySqlCommand("SELECT `firstname` FROM `user` WHERE `unique_id` = @val1");

            GetFirstNameCommand.Parameters.AddWithValue("@val1", user_ID);
            List <string> results = DatabaseClass.GetData(GetFirstNameCommand, true);

            return(results[0]);
        }
Ejemplo n.º 4
0
        public int SelectQuestionID(string difficulty, string category)
        {
            MySqlCommand getMaxId = new MySqlCommand("SELECT `id` FROM `question` WHERE `category` = @val1 AND `difficulty` LIKE @val2 ORDER BY `id` DESC");

            getMaxId.Parameters.AddWithValue("@val1", category);
            getMaxId.Parameters.AddWithValue("@val2", difficulty);
            List <string> Id = DatabaseClass.GetData(getMaxId, true);

            return(random.Next(0, Convert.ToInt32(Id[0])));
        }
Ejemplo n.º 5
0
 public List <ScoreboardDTO> ConvertToList(List <string> scoreboardID, List <ScoreboardDTO> ScoreboardData)
 {
     foreach (string ID in scoreboardID)
     {
         MySqlCommand GetScoreboardID = new MySqlCommand("SELECT * FROM `scoreboard` WHERE `id` = @val1");
         GetScoreboardID.Parameters.AddWithValue("@val1", ID);
         var results = DatabaseClass.GetData(GetScoreboardID, true);
         ScoreboardData.Add(new ScoreboardDTO(results[0], results[1], results[2], results[3], results[4], results[5], results[6], Convert.ToDateTime(results[7])));
     }
     foreach (ScoreboardDTO user in ScoreboardData)
     {
         user.FirstName = GetNameFromUniqueID(Convert.ToString(user.UserID));
     }
     return(ScoreboardData);
 }
Ejemplo n.º 6
0
        UserDTO ILoginDatabaseContext.GetLoginData(string email, string password)
        {
            MySqlCommand getUserData = new MySqlCommand("SELECT `unique_id`,`firstname`,`lastname` FROM user WHERE email=@val1 AND password=@val2");

            getUserData.Parameters.AddWithValue("@val1", email);
            getUserData.Parameters.AddWithValue("@val2", password);
            List <string> results = DatabaseClass.GetData(getUserData, true);

            if (results != null && results.Count > 0)
            {
                return(new UserDTO {
                    UniqueID = results[0], FirstName = results[1], LastName = results[2], Email = email
                });
            }
            return(null);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public IEnumerable <ScoreboardDTO> SelectScoreboardData(string difficulty, int category, string timeSpan)
        {
            List <ScoreboardDTO> ListScoreboardData = new List <ScoreboardDTO>();

            if (difficulty == "0" || category == 0)
            {
                category   = 15;
                difficulty = "easy";
            }
            DateTime now       = DateTime.Now;
            DateTime startDate = now;

            switch (timeSpan)
            {
            case "PastWeek":
                startDate = now.AddDays(-7);
                break;

            case "PastMonth":
                startDate = now.AddDays(-30);
                break;

            case "AllTime":
                startDate = now.AddYears(-40);
                break;
            }
            string       startString             = startDate.ToString("yyyy-MM-dd HH:mm:ss");
            MySqlCommand SelectQuestionIDCommand = new MySqlCommand("SELECT `id` FROM `scoreboard` WHERE `category` = @val1 AND `difficulty` LIKE @val2 AND `date` BETWEEN @val3 AND @val4 ORDER BY score DESC LIMIT 5");

            SelectQuestionIDCommand.Parameters.AddWithValue("@val1", category);
            SelectQuestionIDCommand.Parameters.AddWithValue("@val2", difficulty);
            SelectQuestionIDCommand.Parameters.AddWithValue("@val3", startString);
            SelectQuestionIDCommand.Parameters.AddWithValue("@val4", now.ToString("yyyy-MM-dd HH:mm:ss"));
            List <string> scoreboardID = DatabaseClass.GetData(SelectQuestionIDCommand, true);

            ListScoreboardData = ConvertToList(scoreboardID, ListScoreboardData);
            return(ListScoreboardData);
        }
Ejemplo n.º 9
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);
        }