public List <ITournamentEntry> saveTournamentEntry(IMatchup matchup) { ITournamentEntry entry1 = TournamentEntryTable.Get(matchup.MatchupEntries[0].TournamentEntryId, dbConn); ITournamentEntry entry2 = TournamentEntryTable.Get(matchup.MatchupEntries[1].TournamentEntryId, dbConn); if (entry1 == null || entry2 == null) { return(null); } entry1.Wins = matchup.MatchupEntries[0].TheTeam.Wins; entry1.Losses = matchup.MatchupEntries[0].TheTeam.Losses; entry2.Wins = matchup.MatchupEntries[1].TheTeam.Wins; entry2.Losses = matchup.MatchupEntries[1].TheTeam.Losses; List <ITournamentEntry> results = new List <ITournamentEntry>(); if (TournamentEntryTable.Update(entry1, dbConn) == null) { return(null); } if (TournamentEntryTable.Update(entry2, dbConn) == null) { return(null); } results.Add(entry1); results.Add(entry2); return(results); }
private void populateMatchupDetails(IMatchup matchup) { teamOneDataGrid.Items.Clear(); foreach (IPerson p in matchup.MatchupEntries[0].TheTeam.Members) { TournamentViewDataGridItem dataGridItem = new TournamentViewDataGridItem() { PlayerName = p.FirstName + " " + p.LastName, Wins = p.Wins, Losses = p.Losses, TeamId = matchup.MatchupEntries[0].TheTeam.TeamId }; teamOneDataGrid.Items.Add(dataGridItem); } teamTwoDataGrid.Items.Clear(); foreach (IPerson p in matchup.MatchupEntries[1].TheTeam.Members) { TournamentViewDataGridItem dataGridItem = new TournamentViewDataGridItem() { PlayerName = p.FirstName + " " + p.LastName, Wins = p.Wins, Losses = p.Losses, TeamId = matchup.MatchupEntries[1].TheTeam.TeamId }; teamTwoDataGrid.Items.Add(dataGridItem); } }
public IMatchup saveMatchupScore(IMatchup matchup) { MatchupsTable.Update(matchup, dbConn); foreach (var entity in matchup.MatchupEntries) { MatchupEntriesTable.Update(entity, dbConn); } return(matchup); }
public static void NotifyParticipants(IMatchup matchup, ITournament tournament) { List <IMatchupEntry> matchupEntries = matchup.MatchupEntries; string firstTeamName = tournament.Teams.Find(x => x.TeamId == matchupEntries[0].TheTeam.TeamId).TeamName; string secondTeamName = tournament.Teams.Find(x => x.TeamId == matchupEntries[1].TheTeam.TeamId).TeamName; var finals = tournament.Rounds.Max(x => x.RoundNum) == tournament.ActiveRound;; Email(matchupEntries[0], firstTeamName, secondTeamName, tournament.TournamentName, tournament.ActiveRound, finals); Email(matchupEntries[1], secondTeamName, firstTeamName, tournament.TournamentName, tournament.ActiveRound, finals); }
public IMatchup savePersonStats(IMatchup matchup) { List <IPerson> people = PersonsTable.GetAll(dbConn); if (people == null) { return(null); } for (int i = 0; i < matchup.MatchupEntries.Count; i++) { if (i == 0) { if (matchup.MatchupEntries[i].Score > matchup.MatchupEntries[i + 1].Score) { foreach (IPerson person in matchup.MatchupEntries[i].TheTeam.Members) { person.Wins++; PersonsTable.Update(person, dbConn); } } else { foreach (IPerson person in matchup.MatchupEntries[i].TheTeam.Members) { person.Losses++; PersonsTable.Update(person, dbConn); } } } else { if (matchup.MatchupEntries[i].Score > matchup.MatchupEntries[i - 1].Score) { foreach (IPerson person in matchup.MatchupEntries[i].TheTeam.Members) { person.Wins++; PersonsTable.Update(person, dbConn); } } else { foreach (IPerson person in matchup.MatchupEntries[i].TheTeam.Members) { person.Losses++; PersonsTable.Update(person, dbConn); } } } } return(matchup); }
public static IMatchup Create(IMatchup entity, MySqlConnection dbConn) { string query = "INSERT INTO Matchups (round_id, completed) VALUES (@round, @completed)"; Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("@round", entity.RoundId.ToString()); param.Add("@completed", DatabaseHelper.BoolToString(entity.Completed)); var resultsPK = DatabaseHelper.GetNonQueryCount(query, dbConn, param); entity.MatchupId = resultsPK; return(entity); }
public static IMatchup Delete(IMatchup entity, MySqlConnection dbConn) { string query = "DELETE FROM Matchups WHERE matchup_id = @id"; Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("@id", entity.MatchupId.ToString()); var result = DatabaseHelper.GetNonQueryCount(query, dbConn, param); if (result != 0) { return(entity); } return(null); }
public static IMatchup Update(IMatchup entity, MySqlConnection dbConn) { string query = "UPDATE Matchups SET completed = @status WHERE matchup_id = @id"; Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("@status", DatabaseHelper.BoolToString(entity.Completed)); param.Add("@id", entity.MatchupId.ToString()); var result = DatabaseHelper.GetNonQueryCount(query, dbConn, param); if (result != 0) { return(entity); } return(null); }
public bool ScoreMatchup(IMatchup matchup, int team1Score, int team2Score) { matchup.MatchupEntries[0].Score = team1Score; matchup.MatchupEntries[1].Score = team2Score; matchup.Completed = true; //Keep track of wins and losses only in this tournament if (matchup.MatchupEntries[0].Score > matchup.MatchupEntries[1].Score) { matchup.MatchupEntries[0].TheTeam.Wins++; matchup.MatchupEntries[1].TheTeam.Losses++; } else { matchup.MatchupEntries[0].TheTeam.Losses++; matchup.MatchupEntries[1].TheTeam.Wins++; } return(true); }
public IMatchup saveTeamScore(IMatchup matchup) { List <ITeam> allTeams = TeamsTable.GetAll(dbConn); ITeam firstTeam = allTeams.Find(x => x.TeamId == matchup.MatchupEntries[0].TheTeam.TeamId); ITeam secondTeam = allTeams.Find(x => x.TeamId == matchup.MatchupEntries[1].TheTeam.TeamId); if (matchup.MatchupEntries[0].Score > matchup.MatchupEntries[1].Score) { firstTeam.Wins++; secondTeam.Losses++; } else { firstTeam.Losses++; secondTeam.Wins++; } ITeam team1 = TeamsTable.Update(firstTeam, dbConn); ITeam team2 = TeamsTable.Update(secondTeam, dbConn); return(matchup); }