Beispiel #1
0
        public Response GetSeasonItem(string gameId, string seasonId)
        {
            RequestHelper.ValidateId(gameId);
            RequestHelper.ValidateId(seasonId);

            var gameInfo = GetGameInfo(gameId);

            RequestHelper.ValidateId(seasonId);

            var statisticsService = ServiceFactory.CreateStatisticsService(gameInfo);
            var seasonStatistics  = statisticsService.GetSeasonStatistics(seasonId);

            if (seasonStatistics == null)
            {
                throw ResponseHelper.Get404NotFound($"Season with ID '{seasonId}' not found");
            }

            var halDocument = CreateHalDocument(UriHelper.GetSeasonUri(gameId, seasonId), gameInfo);

            var resource = new SeasonStatisticsMapper(UriHelper).Map(seasonStatistics);

            halDocument.AddResource("rel:season", resource);

            var seasonListResourceFactory = new SeasonListResourceFactory(gameInfo, UriHelper, UriHelper.GetSeasonUri(gameId, "###seasonid###"));

            halDocument.AddResource("rel:seasons", seasonListResourceFactory.Create());

            var response = GetResponse(halDocument);

            return(response);
        }
Beispiel #2
0
        public Response GetBySeason(string gameId, string seasonId)
        {
            var game = GetGameInfo(gameId);

            RequestHelper.ValidateId(seasonId);

            //TODO Check season exists and belongs to user.
            //var seasonService = ServiceFactory.CreateSeasonService(game);
            //var season = seasonService.Get(seasonId);

            IEnumerable <LeagueTable> leagueTables;

            try
            {
                var leagueTableService = ServiceFactory.CreateLeagueTableService(game);
                leagueTables = leagueTableService.GetBySeason(seasonId);
            }
            catch (BusinessLogicException businessLogicException)
            {
                throw Handle(businessLogicException);
            }

            var mapper = new LeagueTableMapper(UriHelper);
            var leagueTableResources = new List <Resource>();

            foreach (var leagueTable in leagueTables)
            {
                var resource = mapper.Map(leagueTable, LeagueTableMapper.FullDetails);
                leagueTableResources.Add(resource);
            }

            var halDocument = CreateHalDocument(UriHelper.GetSeasonLeagueTablesUri(gameId, seasonId), game);

            var competitionService     = ServiceFactory.CreateCompetitionService();
            var currentCompetitionName = competitionService.Get(game.CurrentTeam.CurrentLeagueCompetitionId).Name;

            halDocument.AddProperty("current-competition-name", currentCompetitionName);

            halDocument.AddResource("rel:leaguetables", leagueTableResources);

            var seasonListResourceFactory = new SeasonListResourceFactory(game, UriHelper, UriHelper.GetSeasonLeagueTablesUri(gameId, "###seasonid###"));

            halDocument.AddResource("rel:seasons", seasonListResourceFactory.Create());

            var response = GetResponse(halDocument);

            return(response);
        }
Beispiel #3
0
        public Response GetTeamMatches(string gameId, string seasonId, string teamId)
        {
            var game = GetGameInfo(gameId);

            RequestHelper.ValidateId(seasonId);
            RequestHelper.ValidateId(teamId);

            // Check team exists.
            var teamService = ServiceFactory.CreateTeamService(game);
            var team        = teamService.GetTeam(teamId);

            if (team == null)
            {
                throw ResponseHelper.Get404NotFound($"Team with ID '{teamId}' not found");
            }

            var matchService = ServiceFactory.CreateMatchService(game);

            var matches = matchService.GetTeamRoundMatches(teamId, seasonId, team.CurrentLeagueCompetitionId).ToList();

            if (!matches.Any())
            {
                throw ResponseHelper.Get404NotFound($"No matches found for seasonId '{seasonId}' and teamId '{teamId}'");
            }

            var halDocument = CreateHalDocument(UriHelper.GetSeasonTeamMatchesUri(gameId, seasonId, teamId), game);

            halDocument.AddLink("rel:matches-of-team", new Link(UriHelper.GetTeamUri(gameId, teamId)));

            var resourceFactory = new TeamMatchResourceFactory(UriHelper);
            var resources       = resourceFactory.Create(matches, gameId, seasonId, teamId);

            halDocument.AddResource("rel:matches", resources);

            var teamListResourceFactory = new TeamListResourceFactory(game, UriHelper, UriHelper.GetSeasonTeamMatchesUri(gameId, seasonId, "###teamid###"));

            halDocument.AddResource("rel:teams", teamListResourceFactory.Create());

            var seasonListResourceFactory = new SeasonListResourceFactory(game, UriHelper, UriHelper.GetSeasonTeamMatchesUri(gameId, "###seasonid###", teamId));

            halDocument.AddResource("rel:seasons", seasonListResourceFactory.Create());

            return(GetResponse(halDocument));
        }
Beispiel #4
0
        public Response GetSeasonCollection(string gameId)
        {
            RequestHelper.ValidateId(gameId);

            var gameInfo = GetGameInfo(gameId);

            var seasonService = ServiceFactory.CreateSeasonService(gameInfo);
            var seasons       = seasonService.GetAll();

            var halDocument = CreateHalDocument(UriHelper.GetSeasonsUri(gameId), gameInfo);

            var seasonListResourceFactory = new SeasonListResourceFactory(gameInfo, UriHelper, UriHelper.GetSeasonUri(gameId, "###seasonid###"));

            halDocument.AddResource("rel:seasons", seasonListResourceFactory.Create());

            var response = GetResponse(halDocument);

            return(response);
        }