public FinishedMatch GetFinishedMatch(int matchID) { teamrep = new TeamRepository(); DateTime date = Convert.ToDateTime("01-01-1900"); Team homeTeam = new Team(); Team awayTeam = new Team(); decimal multiplierHome = 0; decimal multiplierAway = 0; decimal multiplierDraw = 0; int scoreHome = 0; int scoreAway = 0; MatchResult result = 0; MySqlCommand command = new MySqlCommand("GetMatch"); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@matchID", MySqlDbType.Int32).Value = matchID; MySqlDataReader reader = database.Read(command); while (reader.Read()) { homeTeam.TeamID = (int)reader["HomeTeamID"]; awayTeam.TeamID = (int)reader["AwayTeamID"]; multiplierHome = (decimal)reader["MultiplierHome"]; multiplierAway = (decimal)reader["MultiplierAway"]; multiplierDraw = (decimal)reader["MultiplierDraw"]; date = (DateTime)reader["Date"]; scoreHome = (int)reader["ScoreHome"]; scoreAway = (int)reader["ScoreAway"]; Enum.TryParse((string)reader["Result"], out result); } database.CloseConnection(); homeTeam.TeamName = teamrep.GetName(homeTeam.TeamID); awayTeam.TeamName = teamrep.GetName(awayTeam.TeamID); FinishedMatch match = new FinishedMatch(matchID, homeTeam, awayTeam, multiplierHome, multiplierAway, multiplierDraw, date, scoreHome, scoreAway, result); return(match); }
public List <FinishedMatch> GetFinishedMatches(int isFinished) { teamrep = new TeamRepository(); List <FinishedMatch> matchList = new List <FinishedMatch>(); MySqlCommand command = new MySqlCommand("GetMatches"); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@isFinished", MySqlDbType.Bit).Value = isFinished; MySqlDataReader reader = database.Read(command); while (reader.Read()) { int matchID = (int)reader["MatchID"]; Team homeTeam = new Team(); Team awayTeam = new Team(); homeTeam.TeamID = (int)reader["HomeTeamID"]; awayTeam.TeamID = (int)reader["AwayTeamID"]; decimal multiplierHome = (decimal)reader["MultiplierHome"]; decimal multiplierAway = (decimal)reader["MultiplierAway"]; decimal multiplierDraw = (decimal)reader["MultiplierDraw"]; DateTime date = (DateTime)reader["Date"]; int scoreHome = (int)reader["ScoreHome"]; int scoreAway = (int)reader["ScoreAway"]; Enum.TryParse((string)reader["Result"], out MatchResult result); FinishedMatch match = new FinishedMatch(matchID, homeTeam, awayTeam, multiplierHome, multiplierAway, multiplierDraw, date, scoreHome, scoreAway, result); matchList.Add(match); } database.CloseConnection(); //Hier worden de ID's en namen van de teams uit de database gehaald en in de lijst geplaatst. foreach (FinishedMatch m in matchList) { m.HomeTeam.TeamName = teamrep.GetName(m.HomeTeam.TeamID); m.AwayTeam.TeamName = teamrep.GetName(m.AwayTeam.TeamID); } return(matchList); }