public static void assignStats(Result result, ApplicationDbContext db, string tournamentName, Fixture fixture) { List <Team> teamInFixture = findTeams(result, db.Teams.ToList()); Team homeTeam = teamInFixture.ElementAt(0); Team awayTeam = teamInFixture.ElementAt(1); // filter with teamId and tournamentName TeamTournamentStat statForHomeTeamTobeModified = db.teamTournamentStats.ToList().First(x => x.teamId == homeTeam.id && x.tournamentName == tournamentName); TeamTournamentStat statForAwayTeamTobeModified = db.teamTournamentStats.ToList().First(x => x.teamId == awayTeam.id && x.tournamentName == tournamentName); assignDefaultStats(statForHomeTeamTobeModified, statForAwayTeamTobeModified, result); Tournament tourn = db.Tournaments.ToList().First(x => x.name == tournamentName); tourn.results = db.Results.Where(x => x.fixtureId == result.fixtureId).ToList(); if (tourn.results.Count > 12) { Helper.ChangeTeamStatus(db.teamTournamentStats.ToList(), tourn); } db.SaveChanges(); }
public static void assignDefaultStats(TeamTournamentStat homeStats, TeamTournamentStat awayStats, Result result) { homeStats.gamesPlayed++; homeStats.goalsFor += result.homeGoals; homeStats.goalsAgainst += result.awayaGoals; homeStats.getGoalDiff(); awayStats.gamesPlayed++; awayStats.goalsFor += result.awayaGoals; awayStats.goalsAgainst += result.homeGoals; awayStats.getGoalDiff(); PopulateGamesWon(homeStats, awayStats, result); }
public static int getGamesPlayedInTournament(Team team, string tournName, ApplicationDbContext db) { Tournament tourn = db.Tournaments.ToList().First(x => x.name == tournName); TeamTournamentStat tournStat = null; if (hasTeamPlayedTourn(team, tournName)) { tournStat = db.teamTournamentStats.ToList().First(x => x.tournamentName == tourn.name && x.teamId == team.id); } else { return(0); } return(tournStat.gamesPlayed); }
public static void assignDefaultStats(string tournamentName, Team homeTeam, Team awayTeam, Result result, ApplicationDbContext db) { TeamTournamentStat homeStats = db.teamTournamentStats.ToList().First(x => x.teamId == homeTeam.id && x.tournamentName == tournamentName); TeamTournamentStat awayStats = db.teamTournamentStats.ToList().First(x => x.teamId == awayTeam.id && x.tournamentName == tournamentName); homeStats.gamesPlayed++; homeStats.goalsFor += result.homeGoals; homeStats.goalsAgainst += result.awayaGoals; homeStats.getGoalDiff(); awayStats.gamesPlayed++; awayStats.goalsFor += result.awayaGoals; awayStats.goalsAgainst += result.homeGoals; awayStats.getGoalDiff(); PopulateGamesWon(homeStats, awayStats, result, db); }
private static void PopulateGamesWon(TeamTournamentStat homeTeam, TeamTournamentStat awayTeam, Result result) { if (result.homeGoals > result.awayaGoals) { homeTeam.gamesWon++; homeTeam.points += 3; awayTeam.gamesLost++; } else if (result.homeGoals < result.awayaGoals) { awayTeam.gamesWon++; awayTeam.points += 3; homeTeam.gamesLost++; } else { homeTeam.gamesDrawn++; awayTeam.gamesDrawn++; homeTeam.points++; awayTeam.points++; } }
private static void PopulateGamesWon(TeamTournamentStat homeTeam, TeamTournamentStat awayTeam, Result result, ApplicationDbContext db) { if (result.homeGoals > result.awayaGoals) { homeTeam.gamesWon++; homeTeam.points += 3; awayTeam.gamesLost++; } else if (result.homeGoals < result.awayaGoals) { awayTeam.gamesWon++; awayTeam.points += 3; homeTeam.gamesLost++; } else { homeTeam.gamesDrawn++; awayTeam.gamesDrawn++; homeTeam.points++; awayTeam.points++; } db.SaveChanges(); }