public void createTournamentGame(TournamentMatch gameModel) { SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = connectionString; try { myConnection.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = myConnection; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "Create_TournamentGame"; cmd.Parameters.Add(new SqlParameter("@TeamOneId", gameModel.teamOne.Id)); cmd.Parameters.Add(new SqlParameter("@TeamTwoId", gameModel.teamTwo.Id)); cmd.Parameters.Add(new SqlParameter("@IsPlayed", false)); cmd.Parameters.Add(new SqlParameter("@TournamentId", gameModel.tournamentId)); cmd.Parameters.Add(new SqlParameter("@TournamentRound", gameModel.TournamentRound)); cmd.ExecuteNonQuery(); } catch (Exception e) { throw e; } finally { myConnection.Close(); } }
public List <TournamentMatch> getTournamentGamesByTourId(int tournamentId) { SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = connectionString; //Adding Games to GamesList try { myConnection.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = myConnection; cmd.Parameters.Add("@tournamentId", SqlDbType.Int); cmd.Parameters["@tournamentId"].Value = tournamentId; cmd.CommandText = "SELECT * FROM dbo.TournamentGames Where TournamentId=@tournamentId"; SqlDataReader myreader = cmd.ExecuteReader(); List <TournamentMatch> tournanmentMatches = new List <TournamentMatch>(); while (myreader.Read()) { TournamentMatch tmpTournamentMatch = new TournamentMatch(); tmpTournamentMatch.teamOne = GetTeamById((int)myreader["TeamIdOne"]); tmpTournamentMatch.teamTwo = GetTeamById((int)myreader["TeamIdTwo"]); tmpTournamentMatch.TournamentRound = (int)myreader["TournamentRound"]; tmpTournamentMatch.isPlayed = (bool)myreader["isPlayed"]; tmpTournamentMatch.Id = (int)myreader["Id"]; if (tmpTournamentMatch.isPlayed) { tmpTournamentMatch.Result = (string)myreader["Result"]; tmpTournamentMatch.isTeamOneWinner = (bool)myreader["IsTeamOneWinner"]; } tmpTournamentMatch.tournamentId = (int)myreader["TournamentId"]; tournanmentMatches.Add(tmpTournamentMatch); } return(tournanmentMatches); } catch (Exception e) { throw e; } finally { myConnection.Close(); } }
public TournamentMatch getTournamentMatchByid(int id) { SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = connectionString; //Adding Games to GamesList try { myConnection.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = myConnection; cmd.Parameters.Add("@matchId", SqlDbType.Int); cmd.Parameters["@matchId"].Value = id; cmd.CommandText = "SELECT * FROM dbo.TournamentGames Where Id=@matchId"; SqlDataReader myreader = cmd.ExecuteReader(); TournamentMatch theMatch = new TournamentMatch(); while (myreader.Read()) { theMatch.teamOne = GetTeamById((int)myreader["TeamIdOne"]); theMatch.teamTwo = GetTeamById((int)myreader["TeamIdTwo"]); theMatch.TournamentRound = (int)myreader["TournamentRound"]; theMatch.isPlayed = (bool)myreader["isPlayed"]; //tmpTournamentMatch.isTeamOneWinner = (bool)myreader["IsTeamOneWinner"]; theMatch.tournamentId = (int)myreader["TournamentId"]; theMatch.Id = (int)myreader["Id"]; } return(theMatch); } catch (Exception e) { throw e; } finally { myConnection.Close(); } }