Пример #1
0
        /// <summary>
        /// Get all tournaments in a list
        /// </summary>
        /// <returns>List with TournamentItems</returns>
        public List <TournamentModel> GetTournaments()
        {
            List <TournamentModel>  tournaments             = new List <TournamentModel>();
            EventLocationController eventLocationController = new EventLocationController();
            PlayerController        playerController        = new PlayerController();

            try
            {
                this.Connection.Open();

                string          query  = @"SELECT * FROM tournament ORDER BY date DESC";
                MySqlCommand    cmd    = new MySqlCommand(query, this.Connection);
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    tournaments.Add(
                        new TournamentModel
                    {
                        Id         = reader.GetInt32("id"),
                        Date       = reader.GetDateTime("date").ToLocalTime(),
                        Cost       = reader.GetDecimal("cost"),
                        MinPlayers = reader.GetInt32("min_players"),
                        MinAge     = reader.GetInt32("min_age"),
                        MaxAge     = reader.GetInt32("max_age"),
                        LocationId = reader.GetInt32("location_id"),
                        WinnerId   = reader.IsDBNull(reader.GetOrdinal("winner_id"))
                                               ? -1
                                               : reader.GetInt32("winner_id")
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Fetching tournaments failed. " + e.Message);
                MessageBox.Show("Toernooien ophalen is mislukt.");
            }
            finally
            {
                this.Connection.Close();
            }

            foreach (TournamentModel tournament in tournaments)
            {
                tournament.Location = eventLocationController.GetEventLocation(tournament.Id);
                tournament.Tables   = this.GetTournamentTables(tournament.Id);
                tournament.Entries  = this.GetTournamentEntries(tournament.Id);
                foreach (TournamentTableModel table in tournament.Tables)
                {
                    table.Players = this.GetTournamentTablePlayers(table.Id);
                }
                foreach (TournamentEntryModel entry in tournament.Entries)
                {
                    entry.Player = playerController.GetPlayer(entry.PlayerId);
                }
            }

            return(tournaments);
        }
Пример #2
0
        /// <summary>
        /// Get all Masterclasss in a list
        /// </summary>
        /// <returns>List with MasterclassItems</returns>
        public List <MasterclassModel> GetMasterclasses()
        {
            List <MasterclassModel> masterclasses           = new List <MasterclassModel>();
            EventLocationController eventLocationController = new EventLocationController();
            ProfessionalController  professionalController  = new ProfessionalController();

            try
            {
                this.Connection.Open();

                string          query  = @"SELECT * FROM masterclass ORDER BY date DESC";
                MySqlCommand    cmd    = new MySqlCommand(query, this.Connection);
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    masterclasses.Add(new MasterclassModel
                    {
                        Id             = reader.GetInt32("id"),
                        Date           = reader.GetDateTime("date").ToLocalTime(),
                        MinPlayers     = reader.GetInt32("min_players"),
                        MinRating      = reader.GetInt32("min_rating"),
                        LocationId     = reader.GetInt32("location_id"),
                        ProfessionalId = reader.GetInt32("professional_id")
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Fetching Masterclasss failed. " + e.Message);
                MessageBox.Show("Masterclassen ophalen is mislukt.");
            }
            finally
            {
                this.Connection.Close();
            }

            foreach (MasterclassModel masterclass in masterclasses)
            {
                masterclass.Location     = eventLocationController.GetEventLocation(masterclass.Id);
                masterclass.Professional = professionalController.GetProfessional(masterclass.ProfessionalId);
                masterclass.Entries      = this.GetMasterclassEntries(masterclass.Id);
            }

            return(masterclasses);
        }