public List <Tee> GetTees() { List <Tee> tees = new List <Tee>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GET_TEES, conn); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Tee tee = RowToObject(rdr); Course course = CourseSqlDAO.RowToObject(rdr); tee.Course = course; tees.Add(tee); } } return(tees); } catch (Exception ex) { throw; } }
public List <GolfRound> GetGolfRoundsByPlayerId(int playerId) { List <GolfRound> golfRounds = new List <GolfRound>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GET_GOLF_ROUNDS_BY_PLAYERID, conn); cmd.Parameters.AddWithValue("@playerId", playerId); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { GolfRound golfRound = RowToObject(rdr); Course course = CourseSqlDAO.RowToObject(rdr); Tee tee = TeeSqlDAO.RowToObject(rdr); tee.Course = course; golfRound.Tee = tee; golfRounds.Add(golfRound); } } return(golfRounds); } catch (SqlException ex) { throw; } }
public GolfRound CreateGolfRound(GolfRound round) { GolfRound createdRound = null; try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_CREATE_GOLF_ROUND, conn); cmd.Parameters.AddWithValue("@playerId", round.PlayerId); cmd.Parameters.AddWithValue("@teeId", round.Tee.TeeId); cmd.Parameters.AddWithValue("@datePlayed", round.DatePlayed); cmd.Parameters.AddWithValue("@score", round.Score); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { Tee tee = TeeSqlDAO.RowToObject(rdr); Course course = CourseSqlDAO.RowToObject(rdr); createdRound = RowToObject(rdr); tee.Course = course; createdRound.Tee = tee; } rdr.Close(); if (round.HoleResults.Count > 0) { CreateHoleResults(conn, round, createdRound.GolfRoundId); } return(createdRound); } } catch (Exception ex) { throw; } }
public Tee GetTeeWithHolesById(int teeId) { Tee tee = null; Course course = null; try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GET_TEE_WITH_HOLES_BY_ID, conn); cmd.Parameters.AddWithValue("@teeId", teeId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { tee = TeeSqlDAO.RowToObject(rdr); course = CourseSqlDAO.RowToObject(rdr); tee.Course = course; } if (rdr.NextResult()) { while (rdr.Read()) { Hole hole = HoleSqlDAO.RowToObject(rdr); //hole.Course = course; course.Holes.Add(hole); } } } return(tee); } catch (Exception ex) { throw; } }
public Player GetPlayerById(int playerId) { Player player = null; try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GET_PLAYER_BY_ID, conn); cmd.Parameters.AddWithValue("@playerId", playerId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { player = RowToObject(rdr); } if (rdr.NextResult()) { while (rdr.Read()) { GolfRound golfRound = GolfRoundSqlDAO.RowToObject(rdr); Tee tee = TeeSqlDAO.RowToObject(rdr); Course course = CourseSqlDAO.RowToObject(rdr); tee.Course = course; golfRound.Tee = tee; player.GolfRounds.Add(golfRound); } } return(player); } } catch (SqlException ex) { throw; } }