public int GetGameWeekConceded(int managerId, int gameWeekId, int cupId) { var currentGameWeek = db.GameWeeks.Find(gameWeekId); var fixtures = db.Fixtures.AsNoTracking().Where(x => x.CupId == cupId && x.Round == 1 && x.GameWeek.Number <= currentGameWeek.Number && (x.HomeManagerId == managerId || x.AwayManagerId == managerId)); var manager = db.Managers.Find(managerId); int conceded = 0; foreach (var fixture in fixtures) { var scores = GetScores(fixture.GameWeekId); var homeScore = scores.Where(x => x.ManagerId == fixture.HomeManagerId).FirstOrDefault(); var awayScore = scores.Where(x => x.ManagerId == fixture.AwayManagerId).FirstOrDefault(); var cupScore = new CupScore(fixture.CupId, fixture.FixtureId, fixture.Round, homeScore, awayScore); conceded += cupScore.GetManagerConceded(managerId); } return(conceded); }
public int[] GetGameWeekPoints(int managerId, int gameWeekId, int cupId) { var currentGameWeek = db.GameWeeks.Find(gameWeekId); var fixtures = db.Fixtures.AsNoTracking().Where(x => x.CupId == cupId && x.Round == 1 && x.GameWeek.Number <= currentGameWeek.Number && (x.HomeManagerId == managerId || x.AwayManagerId == managerId)); var manager = db.Managers.Find(managerId); int[] gameWeekPoints = new int[fixtures.Count()]; int i = 0; foreach (var fixture in fixtures) { var scores = GetScores(fixture.GameWeekId); var homeScore = scores.Where(x => x.ManagerId == fixture.HomeManagerId).FirstOrDefault(); var awayScore = scores.Where(x => x.ManagerId == fixture.AwayManagerId).FirstOrDefault(); var cupScore = new CupScore(fixture.CupId, fixture.FixtureId, fixture.Round, homeScore, awayScore); gameWeekPoints[i] = cupScore.GetManagerPoints(managerId); i++; } return(gameWeekPoints); }
public CupViewModel GetData(int cupId) { Cup cup = db.Cups.AsNoTracking().Include(x => x.Groups.Select(g => g.Managers)).Include(x => x.Fixtures).Where(x => x.CupId == cupId).FirstOrDefault(); var gameWeekId = cup.Fixtures.Where(x => x.GameWeek.Complete).OrderByDescending(x => x.GameWeek.Number).Select(x => x.GameWeekId).FirstOrDefault(); CupWeekSummary cupWeekSummary = new CupWeekSummary(); if (gameWeekId != 0) { cupWeekSummary = cupWeekSerializer.DeSerialize(gameWeekId, string.Format("CupWeek_{0}", cup.CupId)); } List <GroupTable> groupTables = new List <GroupTable>(); List <FixtureResult> fixtures = new List <FixtureResult>(); foreach (var group in cup.Groups.OrderBy(x => x.Name)) { Table table = cupWeekSummary.Groups.Where(x => x.GroupId == group.GroupId).FirstOrDefault(); if (table == null) { table = new Table(group.Name, group.GroupId, group.Managers); } groupTables.Add(new GroupTable(group, table)); } var completedGameWeeks = db.GameWeeks.AsNoTracking().Where(x => x.Complete); var fixtureGameWeeks = db.Fixtures.AsNoTracking().Where(x => x.CupId == cup.CupId && completedGameWeeks.Any(p => p.GameWeekId == x.GameWeekId)).Select(x => x.GameWeekId).Distinct(); List <CupScore> cupScores = new List <CupScore>(); foreach (var fixtureGameWeek in fixtureGameWeeks) { cupWeekSummary = cupWeekSerializer.DeSerialize(fixtureGameWeek, string.Format("CupWeek_{0}", cup.CupId)); if (cupWeekSummary != null) { foreach (var cupScore in cupWeekSummary.Scores) { cupScores.Add(cupScore); } } } foreach (var fixture in cup.Fixtures.OrderByDescending(x => x.GameWeek.Number)) { CupScore cupScore = cupScores.Where(x => x.FixtureId == fixture.FixtureId).FirstOrDefault(); if (cupScore != null) { fixtures.Add(new FixtureResult(fixture, cupScore.HomeScore.Margin, cupScore.AwayScore.Margin)); } else { fixtures.Add(new FixtureResult(fixture)); } } return(new CupViewModel(cup, groupTables, fixtures)); }