Beispiel #1
0
        /// <summary>
        /// Reads all the gamers whose gamer tag contains the search request.
        /// </summary>
        /// <param name="gamerRequest"> String of gamer request </param>
        /// <returns> A list of Gamers </returns>
        public List <GamerInfo> ReadGamers(string gamerRequest)
        {
            var DB           = new Database();
            var DQ           = new DatabaseQuery();
            var listOfGamers = new List <GamerInfo>();

            using (MySqlConnection conn = new MySqlConnection(DB.GetConnString()))
            {
                string selectQuery = string.Format("SELECT * FROM gamer_info WHERE gamerTag LIKE \'%{0}%\'", gamerRequest);
                Console.WriteLine(selectQuery);
                MySqlCommand selectCmd = new MySqlCommand(selectQuery, conn);
                conn.Open();
                using (MySqlDataReader reader = selectCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        GamerInfo gamerObj = new GamerInfo();
                        gamerObj.GamerTag     = reader.GetString("gamerTag");
                        gamerObj.BracketCount = DQ.GetBracketCount(gamerObj.GamerTag);
                        gamerObj.Region       = reader.GetString("region");
                        listOfGamers.Add(gamerObj);
                    }
                }
            }
            return(listOfGamers);
        }