public IEnumerable <PlayerStatListItem> SelectPlayer(PlayerStatSelect playerStatSelect) { using (var db = new ApplicationDbContext()) { var query = db .PlayerStats .Where(e => e.CoachID == _userID && e.PlayerID == playerStatSelect.PlayerID) .Select( e => new PlayerStatListItem { PlayerID = e.PlayerID, FullName = e.Player.FullName, YearOfSeason = e.YearOfSeason, GameNumber = e.GameNumber, TeamName = e.Player.Team.TeamName, Goals = e.Goals, Assists = e.Assists, Shots = e.Shots } ); return(query.ToArray()); } }
public ActionResult Index(PlayerStatSelect player) { var players = _db.Players.ToList().Where(t => t.CoachID == Guid.Parse(User.Identity.GetUserId())); ViewBag.PlayerID = new SelectList(players, "PlayerID", "FullName"); var service = CreatePlayerStatService(); if (player.PlayerID == null && player.YearOfSeason == null) { var model = service.GetStats().OrderBy(t => t.TeamName).ThenBy(t => t.PlayerID).ThenBy(t => t.YearOfSeason).ThenBy(t => t.GameNumber); return(View(model)); } else if (player.PlayerID != null && player.YearOfSeason == null) { var model = service.SelectPlayer(player).OrderBy(p => p.YearOfSeason).ThenBy(p => p.GameNumber); return(View(model)); } else if (player.PlayerID == null && player.YearOfSeason != null) { var model = service.SelectSeason(player).OrderBy(p => p.TeamName).ThenBy(p => p.PlayerID).ThenBy(p => p.GameNumber); return(View(model)); } else { var model = service.SelectPlayerAndYear(player).OrderBy(p => p.GameNumber); return(View(model)); } }