public ActionResult EarnedPoints(string userId) { List <Fixture> allFixtures = db.fixturesDB.ToList(); MyVirtualTeam myVirtualTeam = db.myVirtualTeamDB.Find(userId); List <ModelViewEarnedPointsForPlayer> model = new List <ModelViewEarnedPointsForPlayer>(); for (int i = 0; i < myVirtualTeam.footballPlayers.Count; i++) { FootballPlayer player = myVirtualTeam.footballPlayers.ElementAt(i); ModelViewEarnedPointsForPlayer m = new ModelViewEarnedPointsForPlayer(); m.footballPlayer = player; for (int j = 0; j < allFixtures.Count; j++) { Fixture fixture = allFixtures.ElementAt(j); EarnedPointsPerFixture e = new EarnedPointsPerFixture(); e.fixture = fixture; for (int k = 0; k < fixture.matches.Count; k++) { Match match = fixture.matches.ElementAt(k); for (int t = 0; t < match.goals.Count; t++) { if (match.goals.ElementAt(t).footballPlayers.ElementAt(0).id == player.id) { //scorer e.numOfGoalsScored++; } if (match.goals.ElementAt(t).footballPlayers.ElementAt(1).id == player.id) { //goal assisted by e.numOfGoalAssists++; } } if (player.TeamId == match.homeTeamId) { if (match.homeScore > match.awayScore) { e.numOfTeamWinsForPlayer = 1; } if (match.matchStats.homeBallPosession > match.matchStats.awayBallPosession) { e.numOfPlayersWithMoreBallPosessionPerMatch = 1; } if (match.matchStats.homeTotalShoots > match.matchStats.awayTotalShoots) { e.numOfPlayersWithMoreBallTotalShootsPerMatch = 1; } if (match.matchStats.homePasses > match.matchStats.awayPasses) { e.numOfPlayersWithMorePassesPerMatch = 1; } if (match.matchStats.homeFouls > match.matchStats.awayFouls) { e.numOfPlayersWithMoreFoulsPerMatch = 1; } if (match.matchStats.homeCorners > match.matchStats.awayCorners) { e.numOfPlayersWithMoreCornersPerMatch = 1; } if (match.matchStats.homeYellowCards > match.matchStats.awayYellowCards) { e.numOfPlayersWithMoreYellowCardsPerMatch = 1; } if (match.matchStats.homeRedCards > match.matchStats.awayRedCards) { e.numOfPlayersWithMoreRedCardsPerMatch = 1; } } if (player.TeamId == match.awayTeamId) { if (match.awayScore > match.homeScore) { e.numOfTeamWinsForPlayer = 1; } if (match.matchStats.awayBallPosession > match.matchStats.homeBallPosession) { e.numOfPlayersWithMoreBallPosessionPerMatch = 1; } if (match.matchStats.awayTotalShoots > match.matchStats.homeTotalShoots) { e.numOfPlayersWithMoreBallTotalShootsPerMatch = 1; } if (match.matchStats.awayPasses > match.matchStats.homePasses) { e.numOfPlayersWithMorePassesPerMatch = 1; } if (match.matchStats.awayFouls > match.matchStats.homeFouls) { e.numOfPlayersWithMoreFoulsPerMatch = 1; } if (match.matchStats.awayCorners > match.matchStats.homeCorners) { e.numOfPlayersWithMoreCornersPerMatch = 1; } if (match.matchStats.awayYellowCards > match.matchStats.homeYellowCards) { e.numOfPlayersWithMoreYellowCardsPerMatch = 1; } if (match.matchStats.awayRedCards > match.matchStats.homeRedCards) { e.numOfPlayersWithMoreRedCardsPerMatch = 1; } } e.totalPoints = (e.numOfGoalsScored * 2) + e.numOfGoalAssists + e.numOfTeamWinsForPlayer + e.numOfPlayersWithMoreBallPosessionPerMatch + e.numOfPlayersWithMoreBallTotalShootsPerMatch + e.numOfPlayersWithMorePassesPerMatch - e.numOfPlayersWithMoreFoulsPerMatch + e.numOfPlayersWithMoreCornersPerMatch - e.numOfPlayersWithMoreYellowCardsPerMatch - e.numOfPlayersWithMoreRedCardsPerMatch; } m.earnedPointsPerFixture.Add(e); } model.Add(m); } return(View(model)); }
private int countPointsForVirtualTeam(MyVirtualTeam virtualTeam) { int totalPoints = 0; List <Fixture> allFixtures = db.fixturesDB.ToList(); List <ModelViewEarnedPointsForPlayer> model = new List <ModelViewEarnedPointsForPlayer>(); for (int i = 0; i < virtualTeam.footballPlayers.Count; i++) { FootballPlayer player = virtualTeam.footballPlayers.ElementAt(i); ModelViewEarnedPointsForPlayer m = new ModelViewEarnedPointsForPlayer(); m.footballPlayer = player; for (int j = 0; j < allFixtures.Count; j++) { Fixture fixture = allFixtures.ElementAt(j); EarnedPointsPerFixture e = new EarnedPointsPerFixture(); e.fixture = fixture; for (int k = 0; k < fixture.matches.Count; k++) { Match match = fixture.matches.ElementAt(k); for (int t = 0; t < match.goals.Count; t++) { if (match.goals.ElementAt(t).footballPlayers.ElementAt(0).id == player.id) { //scorer e.numOfGoalsScored++; } if (match.goals.ElementAt(t).footballPlayers.ElementAt(1).id == player.id) { //goal assisted by e.numOfGoalAssists++; } } if (player.TeamId == match.homeTeamId) { if (match.homeScore > match.awayScore) { e.numOfTeamWinsForPlayer = 1; } if (match.matchStats.homeBallPosession > match.matchStats.awayBallPosession) { e.numOfPlayersWithMoreBallPosessionPerMatch = 1; } if (match.matchStats.homeTotalShoots > match.matchStats.awayTotalShoots) { e.numOfPlayersWithMoreBallTotalShootsPerMatch = 1; } if (match.matchStats.homePasses > match.matchStats.awayPasses) { e.numOfPlayersWithMorePassesPerMatch = 1; } if (match.matchStats.homeFouls > match.matchStats.awayFouls) { e.numOfPlayersWithMoreFoulsPerMatch = 1; } if (match.matchStats.homeCorners > match.matchStats.awayCorners) { e.numOfPlayersWithMoreCornersPerMatch = 1; } if (match.matchStats.homeYellowCards > match.matchStats.awayYellowCards) { e.numOfPlayersWithMoreYellowCardsPerMatch = 1; } if (match.matchStats.homeRedCards > match.matchStats.awayRedCards) { e.numOfPlayersWithMoreRedCardsPerMatch = 1; } } if (player.TeamId == match.awayTeamId) { if (match.awayScore > match.homeScore) { e.numOfTeamWinsForPlayer = 1; } if (match.matchStats.awayBallPosession > match.matchStats.homeBallPosession) { e.numOfPlayersWithMoreBallPosessionPerMatch = 1; } if (match.matchStats.awayTotalShoots > match.matchStats.homeTotalShoots) { e.numOfPlayersWithMoreBallTotalShootsPerMatch = 1; } if (match.matchStats.awayPasses > match.matchStats.homePasses) { e.numOfPlayersWithMorePassesPerMatch = 1; } if (match.matchStats.awayFouls > match.matchStats.homeFouls) { e.numOfPlayersWithMoreFoulsPerMatch = 1; } if (match.matchStats.awayCorners > match.matchStats.homeCorners) { e.numOfPlayersWithMoreCornersPerMatch = 1; } if (match.matchStats.awayYellowCards > match.matchStats.homeYellowCards) { e.numOfPlayersWithMoreYellowCardsPerMatch = 1; } if (match.matchStats.awayRedCards > match.matchStats.homeRedCards) { e.numOfPlayersWithMoreRedCardsPerMatch = 1; } } e.totalPoints = (e.numOfGoalsScored * 2) + e.numOfGoalAssists + e.numOfTeamWinsForPlayer + e.numOfPlayersWithMoreBallPosessionPerMatch + e.numOfPlayersWithMoreBallTotalShootsPerMatch + e.numOfPlayersWithMorePassesPerMatch - e.numOfPlayersWithMoreFoulsPerMatch + e.numOfPlayersWithMoreCornersPerMatch - e.numOfPlayersWithMoreYellowCardsPerMatch - e.numOfPlayersWithMoreRedCardsPerMatch; } m.earnedPointsPerFixture.Add(e); } model.Add(m); } for (int y = 0; y < model.Count; y++) { ModelViewEarnedPointsForPlayer mTmp = model.ElementAt(y); List <EarnedPointsPerFixture> eTmp = mTmp.earnedPointsPerFixture; for (int h = 0; h < eTmp.Count; h++) { totalPoints += eTmp.ElementAt(h).totalPoints; } } return(totalPoints); }