Пример #1
0
        public IEnumerable <Resource> Create(IEnumerable <Match> matches, string gameId, string teamIdOnTop, out int numberOfMatches)
        {
            numberOfMatches = 0;

            var matchMapper = new MatchMapper(_uriHelper);
            var teamMapper  = new TeamMapper(_uriHelper);

            var matchesGroupedByCompetitionId = matches.ToLookup(m => m.CompetitionId);
            var competitionResources          = new List <Resource>();

            foreach (var group in matchesGroupedByCompetitionId)
            {
                bool teamIdFound = false;

                var matchesForOneCompetitionResource = new Resource(new Link(_uriHelper.GetHomeUri()));

                var matchResources = new List <Resource>();

                bool first = true;
                foreach (var match in group)
                {
                    if (first)
                    {
                        matchesForOneCompetitionResource.AddProperty("competition-name", match.Round.CompetitionName);
                        matchesForOneCompetitionResource.AddProperty("round-name", match.Round.Name);
                    }

                    if (match.HomeTeamId.Equals(teamIdOnTop, StringComparison.OrdinalIgnoreCase) ||
                        match.AwayTeamId.Equals(teamIdOnTop, StringComparison.OrdinalIgnoreCase))
                    {
                        teamIdFound = true;
                    }

                    var matchResource = matchMapper.Map(match, MatchMapper.HomeScore, MatchMapper.AwayScore, MatchMapper.Played, MatchMapper.HomePenaltyScore, MatchMapper.AwayPenaltyScore, MatchMapper.PenaltiesTaken);
                    matchResource.AddResource("home-team", teamMapper.Map(match.HomeTeam, TeamMapper.TeamName));
                    matchResource.AddResource("away-team", teamMapper.Map(match.AwayTeam, TeamMapper.TeamName));
                    matchResources.Add(matchResource);

                    numberOfMatches++;

                    first = false;
                }

                matchesForOneCompetitionResource.AddResource("rel:matches", matchResources);

                if (teamIdFound)
                {
                    competitionResources.Insert(0, matchesForOneCompetitionResource);
                }
                else
                {
                    competitionResources.Add(matchesForOneCompetitionResource);
                }
            }

            return(competitionResources);
        }
Пример #2
0
        public Resource Map(SeasonStatistics seasonStatistics, params string[] properties)
        {
            bool applyAllProperties = !properties.Any();

            var teamMapper = new TeamMapper(_uriHelper);

            var resource = new Resource(new Link(_uriHelper.GetSeasonUri(seasonStatistics.GameId, seasonStatistics.Id)));

            if (applyAllProperties || properties.Contains(SeasonShortName))
            {
                resource.AddProperty(SeasonShortName, seasonStatistics.Season.ShortName);
            }

            if (applyAllProperties || properties.Contains(SeasonLongName))
            {
                resource.AddProperty(SeasonLongName, seasonStatistics.Season.LongName);
            }

            if (applyAllProperties || properties.Contains(NationalChampion) && seasonStatistics.NationalChampion != null)
            {
                var team = teamMapper.Map(seasonStatistics.NationalChampion, TeamMapper.TeamName);
                resource.AddResource(NationalChampion, team);
            }

            if (applyAllProperties || properties.Contains(NationalChampionRunnerUp) && seasonStatistics.NationalChampionRunnerUp != null)
            {
                var team = teamMapper.Map(seasonStatistics.NationalChampionRunnerUp, TeamMapper.TeamName);
                resource.AddResource(NationalChampionRunnerUp, team);
            }

            if (applyAllProperties || properties.Contains(NationalCupWinner) && seasonStatistics.CupWinner != null)
            {
                var team = teamMapper.Map(seasonStatistics.CupWinner, TeamMapper.TeamName);
                resource.AddResource(NationalCupWinner, team);
            }

            if (applyAllProperties || properties.Contains(NationalCupRunnerUp) && seasonStatistics.CupRunnerUp != null)
            {
                var team = teamMapper.Map(seasonStatistics.CupRunnerUp, TeamMapper.TeamName);
                resource.AddResource(NationalCupRunnerUp, team);
            }

            return(resource);
        }
Пример #3
0
        public IEnumerable <Resource> Create(IEnumerable <TeamRoundMatch> matches, string gameId, string seasonId, string teamId)
        {
            var teamMapper = new TeamMapper(_uriHelper);

            var matchResources = new List <Resource>();

            foreach (var match in matches)
            {
                var matchResource = new Resource(new Link(_uriHelper.GetMatchUri(match.GameId, match.MatchId)));

                matchResource.AddProperty("date", match.MatchDate.ToString("dd-MMM"));
                matchResource.AddProperty("competition-name", match.CompetitionName);
                matchResource.AddProperty("round", match.RoundName);
                matchResource.AddProperty("home-score", match.HomeScore);
                matchResource.AddProperty("away-score", match.AwayScore);
                matchResource.AddProperty("penalties-taken", match.PenaltiesTaken);
                matchResource.AddProperty("home-penalty-score", match.HomePenaltyScore);
                matchResource.AddProperty("away-penalty-score", match.AwayPenaltyScore);
                matchResource.AddProperty("played", match.Played);

                if (match.HomeTeam != null)
                {
                    var homeTeamResource = teamMapper.Map(match.HomeTeam, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition);
                    matchResource.AddResource("home-team", homeTeamResource);
                }

                if (match.AwayTeam != null)
                {
                    var awayTeamResource = teamMapper.Map(match.AwayTeam, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition);
                    matchResource.AddResource("away-team", awayTeamResource);
                }

                matchResources.Add(matchResource);
            }

            return(matchResources);
        }
Пример #4
0
        public IEnumerable <Resource> Create()
        {
            var teamService = new ServiceFactory().CreateTeamService(_gameInfo);
            var teams       = teamService.GetGroupedByLeague().ToList();

            var teamResources = _teamMapper.Map(teams, TeamMapper.TeamName, TeamMapper.LeagueName).ToList();

            for (int i = 0; i < teamResources.Count; i++)
            {
                string contextUri = _contextUriPlaceholder.Replace("###teamid###", teams[i].Id);
                teamResources[i].AddLink("context", new Link(contextUri));
            }

            return(teamResources);
        }
Пример #5
0
        public Resource Map(LeagueTable leagueTable, params string[] properties)
        {
            var teamMapper = new TeamMapper(_uriHelper);

            var leagueTableLink = new Link(_uriHelper.GetCompetitionLeagueTableUri(leagueTable.GameId, leagueTable.SeasonCompetition.SeasonId, leagueTable.SeasonCompetition.CompetitionId));
            var resource        = new Resource(leagueTableLink);

            resource.AddProperty("competition-name", leagueTable.CompetitionName);

            var positions = new List <Resource>();

            foreach (var leagueTablePosition in leagueTable.LeagueTablePositions)
            {
                var position = new Resource(leagueTableLink);

                position.AddResource("team", teamMapper.Map(leagueTablePosition.Team, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition));
                position.AddProperty("position", leagueTablePosition.Position);
                position.AddProperty("played", leagueTablePosition.Matches);
                position.AddProperty("points", leagueTablePosition.Points);

                if (properties.Contains(FullDetails))
                {
                    position.AddProperty("wins", leagueTablePosition.Wins);
                    position.AddProperty("draws", leagueTablePosition.Draws);
                    position.AddProperty("losses", leagueTablePosition.Losses);
                    position.AddProperty("goals-scored", leagueTablePosition.GoalsScored);
                    position.AddProperty("goals-conceded", leagueTablePosition.GoalsConceded);

                    string goalDifference = leagueTablePosition.GoalDifference.ToString();
                    if (leagueTablePosition.GoalDifference > 0)
                    {
                        goalDifference = $"+{goalDifference}";
                    }

                    position.AddProperty("goal-difference", goalDifference);
                }

                positions.Add(position);
            }

            resource.AddResource("positions", positions.ToArray());

            return(resource);
        }