// [OutputCache(Duration = 32000, VaryByParam = "id")] public ActionResult Player(int id) { var data = new PlayerViewModel { Player = repository.Player(id) }; data.Matches = repository.PlayerMatches(id); data.Wins = data.Matches.Count(c => c.Winner.Id == data.Player.Id); data.Loses = data.Matches.Count(c => c.Looser.Id == data.Player.Id); data.LastMatch = data.Matches.Count > 0 ? data.Matches.Max(c => c.DateOfMatch).Value.ToShortDateString() : "No Match on Record"; data.CurrentRank = standingsRepository.CurrentStandings().Where(c => c.Player.Id == id).First().Position; return(View(data)); }
private List <Standing> GetNewStandings(int currentWeekNumber, int nextWeekId) { var matches = repository.GetAllMatches(c => c.LadderWeek, c => c.Winner, c => c.Looser); var currentStandings = standingRepository.CurrentStandings(); var newStandings = new List <Standing>(); foreach (var currentStanding in currentStandings) { var winpoints = matches.Where(c => c.LadderWeek.WeekNumber <= currentWeekNumber && c.WinnerId == currentStanding.PlayerId).Sum(c => c.GetWinnerPoints()); var loosePoints = matches.Where(c => c.LadderWeek.WeekNumber <= currentWeekNumber && c.LooserId == currentStanding.PlayerId).Sum(c => c.GetLooserPoints()); newStandings.Add(new Standing { LadderWeekId = nextWeekId, PlayerId = currentStanding.PlayerId, TotalPoints = winpoints + loosePoints }); } return(newStandings); }