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 List <ITeam> getAllTeams() { var allTeams = TeamsTable.GetAll(dbConn); var allTeamMembers = TeamMembersTable.GetAll(dbConn); var allPersons = PersonsTable.GetAll(dbConn); foreach (var team in allTeams) { var members = allTeamMembers.Where(x => x.TeamId == team.TeamId); foreach (var person in members) { var thePersonRecord = allPersons.Where(x => x.PersonId == person.PersonId).First(); team.TeamMembers.Add(thePersonRecord); } } return(allTeams); }
public List <IPerson> getPeople() { List <IPerson> people = PersonsTable.GetAll(dbConn); if (people == null) { return(null); } foreach (IPerson person in people) { int wins = person.Wins; int losses = person.Losses; person.Ratio = wins + losses == 0 ? 0 : (double)wins / (wins + losses); } return(people); }
public ITournament getTournament(int id) { var tournament = TournamentTable.Get(id, dbConn); var allRounds = RoundsTable.GetAll(dbConn); var allMatchups = MatchupsTable.GetAll(dbConn); var allMatchupEntries = MatchupEntriesTable.GetAll(dbConn); var allTournamentEntries = TournamentEntryTable.GetAll(dbConn); var allTeams = TeamsTable.GetAll(dbConn); var allTeamMembers = TeamMembersTable.GetAll(dbConn); var allPersons = PersonsTable.GetAll(dbConn); var allTournamentPrizes = TournamentPrizesTable.GetAll(dbConn); tournament.TournamentEntries = allTournamentEntries.Where(x => x.TournamentId == tournament.TournamentId).ToList(); tournament.TournamentPrizes = allTournamentPrizes.Where(x => x.TournamentId == tournament.TournamentId).ToList(); foreach (var entry in tournament.TournamentEntries) { var entryMembers = allTeamMembers.Where(x => x.TeamId == entry.TeamId).ToList(); foreach (var member in entryMembers) { entry.Members.Add(allPersons.Find(x => x.PersonId == member.PersonId)); } var theTeam = allTeams.Where(x => x.TeamId == entry.TeamId).First(); tournament.Teams.Add(theTeam); } tournament.Rounds = allRounds.Where(x => x.TournamentId == tournament.TournamentId).ToList(); foreach (var round in tournament.Rounds) { round.Matchups = allMatchups.Where(x => x.RoundId == round.RoundId).ToList(); foreach (var matchup in round.Matchups) { matchup.MatchupEntries = allMatchupEntries.Where(x => x.MatchupId == matchup.MatchupId).ToList(); foreach (var team in matchup.MatchupEntries) { team.TheTeam = tournament.TournamentEntries.Where(x => x.TournamentEntryId == team.TournamentEntryId).First(); } } } return(tournament); }