public int BuySquare(UserBet bet, int home, int away) { if (home == away) { // cannot buy 'tie' squares return(1); } // check if square is available, if it is, set its value to the user's id if (IsSquareAvailable(home, away)) { Squares[home, away] = bet; } else { return(1); // square not available } return(0); }
public static BettingSquares GetGameBets(int gameID) { BettingSquares squares = new BettingSquares(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HockeyPoolConnectionString"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("SELECT * FROM FN_GetGameBets(@gameID)", conn)) { conn.Open(); cmd.Parameters.AddWithValue("@gameID", gameID); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int user = (int)reader["UserID"]; decimal amt = (decimal)reader["BetAmount"]; UserBet bet = new UserBet(user, amt); squares.BuySquare(bet, (int)reader["HomeScore"], (int)reader["AwayScore"]); } } } } return(squares); }