private GamesResult GetGamesResult(int leagueID) { var dataCache = new DataCache(); var teams = TeamsService.GetInstance().GetTeams(leagueID: leagueID, showAll: true, dataCache: dataCache); var games = GamesService.GetInstance().GetGames(leagueID: leagueID, dataCache: dataCache); var gamesResult = new GamesResult() { Teams = teams.Select(t => new TeamsResult() { ID = t.ID, Name = t.Name }).ToList(), Games = games.Select(g => new GameResultBase() { ID = g.ID, GameDate = g.GameDate, Team1ID = g.Team1ID, Team1Name = teams.FirstOrDefault(tm1 => tm1.ID == g.Team1ID)?.Name, Team1Score = g.Team1Score, Team2ID = g.Team2ID, Team2Name = teams.FirstOrDefault(tm2 => tm2.ID == g.Team2ID)?.Name, Team2Score = g.Team2Score }).ToList() }; return(gamesResult); }
public GetTeamsResult AddTeam([FromBody] TeamsResult team) { try { if (team.ID == 0) { TeamsService.GetInstance().AddTeam(ConvertObjects.ConvertType(team)); } else { TeamsService.GetInstance().AddLeagueTeam(team.ID, team.LeagueID); } return(GetTeamsResult(team.LeagueID, team.SportID)); } catch (Exception ex) { throw ex; } }
private TeamResult GetTeamResult(int teamID, int leagueID) { var dataCache = new DataCache(); var team = TeamsService.GetInstance().GetTeam(teamID, leagueID, dataCache: dataCache); var teams = TeamsService.GetInstance().GetTeams(leagueID: team.LeagueID, showAll: true, dataCache: dataCache); var players = PlayersService.GetInstance().GetPlayers(dataCache: dataCache); var playerStats = StatsService.GetInstance().GetAllStats(teamID, team.SportID, leagueID, dataCache: dataCache); var statTypes = GamesService.GetInstance().GetStatTypes(team.SportID).OrderBy(s => s.GridDisplayOrder); var teamResult = new TeamResult() { ID = team.ID, Name = team.Name, Games = team.Games.Select(g => new TeamGameResult() { ID = g.ID, GameDate = g.GameDate, OtherTeamName = g.Team1ID == team.ID ? teams.First(t => t.ID == g.Team2ID).Name : teams.First(t => t.ID == g.Team1ID).Name, DidWin = DidWin(g.Team1ID == team.ID, g.Team1Score, g.Team2Score), HighScore = Math.Max(g.Team1Score, g.Team2Score), LowScore = Math.Min(g.Team1Score, g.Team2Score), }).ToList(), Teams = teams.Select(t => new TeamsResult() { ID = t.ID, Name = t.Name }).ToList(), AvailablePlayers = players.Where(p => !team.Players.Exists(tp => tp.ID == p.ID)).Select(p => new PlayersResult() { ID = p.ID, Name = p.Name, }).ToList(), TeamPlayerStats = playerStats.Select(s => ConvertObjects.ConvertType(s)).ToList(), StatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).ToList(), }; return(teamResult); }
private GetTeamsResult GetTeamsResult(int leagueID, int sportID) { var result = new GetTeamsResult(); var dataCache = new DataCache(); var allTeams = TeamsService.GetInstance().GetTeams(sportID: sportID, dataCache: dataCache); var teams = TeamsService.GetInstance().GetTeams(leagueID: leagueID, dataCache: dataCache); result.Teams = teams.Select(t => new TeamsResult() { ID = t.ID, Name = t.Name }).ToList(); result.AvailableTeams = allTeams .Where(t => !teams.Any(t1 => t1.ID == t.ID)) .GroupBy(t => new { t.ID, t.Name }) .Select(t => new TeamsResult() { ID = t.Key.ID, Name = t.Key.Name }).ToList(); return(result); }
private GameResult GetGameResult(int leagueID, int gameID) { try { var dataCache = new DataCache(); var game = GamesService.GetInstance().GetGame(gameID, dataCache: dataCache); var teams = new List <int>() { game.Team1ID, game.Team2ID }; var allTeams = TeamsService.GetInstance().GetTeams(leagueID: leagueID, validTeams: teams, dataCache: dataCache); var players = PlayersService.GetInstance().GetPlayers(gameID: gameID, leagueID: leagueID, dataCache: dataCache); var statTypes = GamesService.GetInstance().GetStatTypes(game.SportID, dataCache: dataCache).OrderBy(s => s.GridDisplayOrder); var gameState = BaseballService.GetInstance().GetExistingGameState(gameID, leagueID, dataCache: dataCache); int?playerAtBat = gameState.TopOfInning ? gameState.Team1Player?.ID : gameState.Team2Player?.ID; var gameResult = new GameResult() { ID = game.ID, GameDate = game.GameDate, StatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).ToList(), QuickStatTypes = statTypes .Where(st => st.QuickButtonOrder > 0) .Select(s => ConvertObjects.ConvertType(s)) .OrderBy(s => s.QuickButtonOrder) .ToList(), Team1ID = game.Team1ID, Team1Score = game.Team1Score, Team1Name = game.Team1Name, Team2ID = game.Team2ID, Team2Score = game.Team2Score, Team2Name = game.Team2Name, Team1PlayerStats = game.PlayerStats .Where(p => p.TeamID == game.Team1ID) .Select(g => { var order = Convert.ToInt16(g.Stats.Where(s => s.StatType.ID == (int)CalculatedStatTypes.BattingOrder).Sum(s => s.Value)); return(new PlayerStatsResult() { PlayerID = g.PlayerID, PlayerName = players.FirstOrDefault(p => p.ID == g.PlayerID)?.Name, PlayerNumber = players.FirstOrDefault(p => p.ID == g.PlayerID)?.Number ?? 0, Order = order == 0 ? (int?)null : order, AtBat = game.SportID == (int)SportsList.Baseball && g.PlayerID == playerAtBat, PlayerStats = g.Stats.OrderBy(s => s.StatType.GridDisplayOrder) .Select(s => new StatResult() { StatTypeID = s.StatType.ID, Name = s.StatType.Name, DefaultShow = s.StatType.DefaultShow, Value = s.Value }).ToList() }); }) .ToList(), Team2PlayerStats = game.PlayerStats .Where(p => p.TeamID == game.Team2ID) .Select(g => { var order = Convert.ToInt16(g.Stats.Where(s => s.StatType.ID == (int)CalculatedStatTypes.BattingOrder).Sum(s => s.Value)); return(new PlayerStatsResult() { PlayerID = g.PlayerID, PlayerName = players.FirstOrDefault(p => p.ID == g.PlayerID)?.Name, PlayerNumber = players.FirstOrDefault(p => p.ID == g.PlayerID)?.Number ?? 0, Order = order == 0 ? (int?)null : order, AtBat = game.SportID == (int)SportsList.Baseball && g.PlayerID == playerAtBat, PlayerStats = g.Stats.OrderBy(s => s.StatType.GridDisplayOrder) .Select(s => new StatResult() { StatTypeID = s.StatType.ID, Name = s.StatType.Name, DefaultShow = s.StatType.DefaultShow, Value = s.Value }).ToList() }); }) .ToList(), Teams = allTeams.Select(t => new TeamsResult() { ID = t.ID, Name = t.Name }) .ToList() }; if (game.SportID == (int)SportsList.Baseball) { gameResult.Team1PlayerStats = gameResult.Team1PlayerStats.OrderBy(p => p.Order == 0 || p.Order == null ? 99 : p.Order).ToList(); gameResult.Team2PlayerStats = gameResult.Team2PlayerStats.OrderBy(p => p.Order == 0 || p.Order == null ? 99 : p.Order).ToList(); gameResult.BaseballGameStateResult = ConvertObjects.ConvertType(BaseballService.GetInstance().GetExistingGameState(gameID, leagueID)); } return(gameResult); } catch (Exception ex) { throw ex; } }