private Models.ScorecardViewModel getTeamScore(int teamID) { ScoreRepository scoreRepo = new ScoreRepository(); IEnumerable <Score> teamScores = scoreRepo.GetAll().Where(x => x.TeamID == teamID).OrderBy(x => x.HoleID); HoleRepository holeRepo = new HoleRepository(); ClosestToPinRepository closestRepo = new ClosestToPinRepository(); IEnumerable <Hole> holeList = holeRepo.GetAll(); List <Models.Scorecard> scoresWithHoleInfo = new List <Models.Scorecard>(); int counter = 0; foreach (var hole in holeList.Where(x => x.SegmentID == 1 || x.SegmentID == 2)) { int holeNumber = counter < 9 ? hole.Number : 9 + hole.Number; counter++; Models.Scorecard sc = new Models.Scorecard(); sc.HoleID = hole.ID; sc.HoleNumber = holeNumber; sc.ParValue = hole.Par; sc.ParValueDisplay = String.Format("Par {0}", hole.Par); sc.TeamID = teamID; Score score = teamScores.Where(x => x.HoleID == hole.ID).SingleOrDefault(); if (score != null) { sc.Value = score.Value; sc.ID = score.ID; sc.DateInserted = score.DateInserted; sc.DateUpdated = score.DateUpdated; } if (hole.Par == 3) { ClosestToPin closest = closestRepo.GetAll().OrderBy(d => d.Distance).Where(h => h.HoleID == hole.ID).FirstOrDefault(); if (closest != null) { sc.Closest.ClosestName = closest.Name; sc.Closest.ClosestDistance = closest.Distance; } } scoresWithHoleInfo.Add(sc); } Models.ScorecardViewModel vm = new Models.ScorecardViewModel() { scores = scoresWithHoleInfo }; return(vm); }
// GET: Scores public ActionResult Index() { List <Score> scores = repo.GetAll().OrderBy(s => s.Game.name).ThenBy(s => s.score1).ToList(); return(View(ToViewModel(scores))); }