private PlayerResource GetPlayerResource(Player player) { var playerResource = PlayerResourceFactory.Create(player); // Team. if (player.Team != null) { var links = new TeamLinks(player.TeamId); var teamResource = TeamResourceFactory.Create(player.Team, links, false); playerResource.Team = teamResource; } // Positions. var position = PositionFactory.Create(player.PreferredPosition); playerResource.PreferredPosition = position; if (player.CurrentPosition != null) { position = PositionFactory.Create(player.CurrentPosition); playerResource.CurrentPosition = position; } // Rating. var rating = RatingFactory.Create(player.Rating); playerResource.Rating = rating; // Skills. playerResource.Skills = new List<PlayerSkill>(); foreach (var skillScore in player.SkillScores) { var skillResource = PlayerSkillFactory.Create(skillScore); playerResource.Skills.Add(skillResource); } return playerResource; }
public static TeamResource Create(Team team, TeamLinks teamLinks, bool fullResource) { var teamResource = new TeamResource(team.Id) { Name = team.Name, }; if (team.CurrentLeagueCompetition != null) { var leagueResource = new LeagueResource(team.CurrentLeagueCompetitionId) { Name = team.CurrentLeagueCompetition.Name, }; teamResource.League = leagueResource; teamResource.LeaguePosition = team.CurrentLeaguePosition; } if (fullResource) { var ratingResource = RatingFactory.Create(team.Rating); teamResource.Rating = ratingResource; var formationResource = FormationResourceFactory.Create(team.Formation); teamResource.Formation = formationResource; } return teamResource; }
private MatchResource GetMatchResource(Match match) { var links = new TeamLinks(match.HomeTeamId); var homeTeamResource = TeamResourceFactory.Create(match.HomeTeam, links, false); links = new TeamLinks(match.AwayTeamId); var awayTeamResource = TeamResourceFactory.Create(match.AwayTeam, links, false); string competitionName = match.Round.CompetitionName; string roundName = match.Round.Name; var matchResource = MatchResourceFactory.Create(match); matchResource.HomeTeam = homeTeamResource; matchResource.AwayTeam = awayTeamResource; matchResource.Competition = competitionName; matchResource.Round = roundName; return matchResource; }
private TeamResource GetTeamResource(Team team) { var links = new TeamLinks(team.Id); var teamResource = TeamResourceFactory.Create(team, links, true); return teamResource; }
public HttpResponseMessage Get(string gameId) { RequestHelper.ValidateId(gameId); Game game; bool gameBelongsToUser = TryFindGameForCurrentUser(gameId, out game); if (!gameBelongsToUser) { throw ResponseHelper.Get404NotFound($"Game ID '{gameId}' not found"); } GameResource gameResource = null; if (game.CurrentTeam == null) { //TODO Nu moet je eerst een team kiezen, dus iets met links/forms //gameResource.Links.Add(UriFactory.GetTeamsToChooseFromLink(gameId)); throw ResponseHelper.Get501NotImplemented("You must pick a team now, but this is not implemented yet..."); } else { var seasonService = ServiceFactory.CreateSeasonService(game); var currentSeason = seasonService.GetCurrentSeason(); var thisSeason = GetSeasonResource(currentSeason, game.CurrentTeam); var links = new TeamLinks(game.CurrentTeamId); var myTeam = TeamResourceFactory.Create(game.CurrentTeam, links, true); var matchService = ServiceFactory.CreateMatchService(game); var nextMatchDay = matchService.GetNextMatchDay(currentSeason.Id); string dateForLink = nextMatchDay.ToString("yyyyMMddHH"); var gameLinks = new GameLinks(gameId, currentSeason.Id, dateForLink); gameResource = GameResourceFactory.Create(game, thisSeason, myTeam, gameLinks); } var response = GetResponse(gameResource); return response; }