public List <Bet> GetBetsByMatch(FinishedMatch match) { List <Bet> BetList = new List <Bet>(); MySqlCommand command = new MySqlCommand(@"SELECT * FROM bets WHERE MatchID = @matchid;"); command.Parameters.AddWithValue("@matchid", match.MatchID); MySqlDataReader reader = database.Read(command); while (reader.Read()) { Enum.TryParse((string)reader["Prediction"], out MatchResult prediction); Enum.TryParse((string)reader["Result"], out BetResult result); Bet bet = new Bet { BetID = (int)reader["BetID"], UserID = (int)reader["UserID"], MatchID = (int)reader["MatchID"], Amount = (decimal)reader["Amount"], Prediction = prediction, HasEnded = (bool)reader["HasEnded"], Result = result, Earned = (decimal)reader["Earned"] }; BetList.Add(bet); } database.CloseConnection(); return(BetList); }
public void GenerateResult(UpcomingMatch match) { teamservice = new TeamService(); betservice = new BetService(); Random random = new Random(); int scoreHome = random.Next(0, 5); int scoreAway = random.Next(0, 5); MatchResult result; if (scoreHome > scoreAway) { result = MatchResult.HomeTeam; } else if (scoreHome < scoreAway) { result = MatchResult.AwayTeam; } else { result = MatchResult.Draw; } FinishedMatch finishedmatch = new FinishedMatch(match.MatchID, match.HomeTeam, match.AwayTeam, match.MultiplierHome, match.MultiplierAway, match.MultiplierDraw, match.Date, scoreHome, scoreAway, result); matchrep.Update(finishedmatch); teamservice.CalculatePoints(finishedmatch); betservice.Payout(finishedmatch); }
public void CalculatePoints(FinishedMatch match) { int homePoints = 0; int awayPoints = 0; int homeWin = 0; int awayWin = 0; int homeLoss = 0; int awayLoss = 0; int draw = 0; if (match.ScoreHome > match.ScoreAway) { homePoints = 3; homeWin = 1; awayLoss = 1; } else if (match.ScoreHome < match.ScoreAway) { awayPoints = 3; awayWin = 1; homeLoss = 1; } else if (match.ScoreHome == match.ScoreAway) { homePoints = 1; awayPoints = 1; draw = 1; } Team hometeam = new Team { TeamID = match.HomeTeam.TeamID, GoalsFor = match.ScoreHome, GoalsAgainst = match.ScoreAway, GamesWon = homeWin, GamesLost = homeLoss, Draws = draw, Points = homePoints }; Team awayteam = new Team { TeamID = match.AwayTeam.TeamID, GoalsFor = match.ScoreAway, GoalsAgainst = match.ScoreHome, GamesWon = awayWin, GamesLost = awayLoss, Draws = draw, Points = awayPoints }; TeamRep.Update(hometeam); TeamRep.Update(awayteam); }
public void Update(FinishedMatch match) { MySqlCommand command = new MySqlCommand(@"UPDATE matches SET `IsFinished`= @isfinished,`ScoreHome`= @scorehome,`ScoreAway`= @scoreaway, `Result`= @result WHERE MatchID = @matchid;"); command.Parameters.AddWithValue("@isfinished", 1); command.Parameters.AddWithValue("@scorehome", match.ScoreHome); command.Parameters.AddWithValue("@scoreaway", match.ScoreAway); command.Parameters.AddWithValue("@result", match.Result.ToString()); command.Parameters.AddWithValue("@matchid", match.MatchID); database.ExecuteCMD(command); }
public void Payout(FinishedMatch match) { List <Bet> betList = new List <Bet>(); betList = betrep.GetBetsByMatch(match); foreach (Bet bet in betList) { if (bet.Prediction == match.Result) { userservice = new UserService(); User user = new User { UserID = bet.UserID, Balance = userservice.GetBalance(bet.UserID) }; if (bet.Prediction == MatchResult.HomeTeam) { bet.Earned = bet.Amount * match.MultiplierHome; } else if (bet.Prediction == MatchResult.AwayTeam) { bet.Earned = bet.Amount * match.MultiplierAway; } else { bet.Earned = bet.Amount * match.MultiplierDraw; } bet.Result = BetResult.Won; betrep.Update(bet); userservice.AddFunds(user, bet.Earned); } else { bet.Result = BetResult.Lost; bet.Earned = 0; betrep.Update(bet); } } }
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); }
protected override void OnMatchFini(int vainqueurId) { base.OnMatchFini(vainqueurId); FinishedMatch?.Invoke(this, new WinnerEventArgs(vainqueurId)); }