public async Task <IReadOnlyCollection <MatchModel> > GetAllMatches()
        {
            var players = await playersApiClient.GetAllPlayers();

            var matches = await matchesApiClient.GetAllMatches();

            return(MatchMapper.Map(matches, players));
        }
        public async Task <MatchModel> GetMatchById(string id)
        {
            var match = await matchesApiClient.GetMatch(id);

            Player loser = await playersApiClient.GetPlayer(match.LoserId);

            Player winner = await playersApiClient.GetPlayer(match.WinnerId);

            return(MatchMapper.Map(match, new List <Player> {
                loser, winner
            }));
        }
Beispiel #3
0
        public Response GetItem(string gameId, string matchId)
        {
            var gameInfo = GetGameInfo(gameId);

            RequestHelper.ValidateId(matchId);

            var matchService = ServiceFactory.CreateMatchService(gameInfo);
            var match        = matchService.GetMatch(matchId);

            if (match == null)
            {
                throw ResponseHelper.Get404NotFound($"Match ID '{matchId}' not found");
            }

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

            var matchMapper = new MatchMapper(UriHelper);

            var matchResource = matchMapper.Map(
                match,
                MatchMapper.HomeScore,
                MatchMapper.AwayScore,
                MatchMapper.PenaltiesTaken,
                MatchMapper.HomePenaltyScore,
                MatchMapper.AwayPenaltyScore,
                MatchMapper.Date,
                MatchMapper.Played,
                MatchMapper.Round);

            var teamMapper       = new TeamMapper(UriHelper);
            var homeTeamResource = teamMapper.Map(match.HomeTeam, TeamMapper.TeamName);
            var awayTeamResource = teamMapper.Map(match.AwayTeam, TeamMapper.TeamName);

            matchResource.AddResource("home-team", homeTeamResource);
            matchResource.AddResource("away-team", awayTeamResource);

            halDocument.AddResource("rel:match", matchResource);

            AddPlayNextMatchDayForm(gameInfo, halDocument, match.Date);

            // Add the other matches that are played on this match day. Unless there is only one match, then there's no need to add these matches.
            //var matchesPerCompetition = GetDayMatchesResources(gameInfo, match.Date, out int numberOfMatches);
            //if (numberOfMatches > 1)
            //{
            //   halDocument.AddResource("rel:matches-per-competition", matchesPerCompetition);
            //}

            var response = GetResponse(halDocument);

            return(response);
        }
        public async Task <MatchModel> CreateMatch(CreateMatchCommand command)
        {
            Player winner = await playersApiClient.GetPlayer(command.WinnerId);

            Player loser = await playersApiClient.GetPlayer(command.LoserId);

            PlayersRatings ratings = await ratingApiClient.CalculatePlayersRatings(RatingMapper.Map(winner, loser));

            UpdatePlayerRequest updateWinnerRequest = new UpdatePlayerRequest(winner.Id, winner.Name, ratings.WinnerRating.Rating, ratings.WinnerRating.Deviation, ratings.WinnerRating.Volatility);

            winner = await playersApiClient.UpdatePlayer(updateWinnerRequest);

            UpdatePlayerRequest updateLoserRequest = new UpdatePlayerRequest(loser.Id, loser.Name, ratings.LoserRating.Rating, ratings.LoserRating.Deviation, ratings.LoserRating.Volatility);

            loser = await playersApiClient.UpdatePlayer(updateLoserRequest);

            CreateMatchRequest createMatchRequest = new CreateMatchRequest(winner.Id, loser.Id, command.Score);
            Match match = await matchesApiClient.CreateMatch(createMatchRequest);

            return(MatchMapper.Map(match, new List <Player> {
                winner, loser
            }));
        }
Beispiel #5
0
 public List <MatchDTO> List()
 {
     return(this.ListEntities().Select(obj => MatchMapper.Map(obj)).ToList());
 }
Beispiel #6
0
 public MatchDTO Get(int MatchID)
 {
     return(MatchMapper.Map(this.GetEntity(MatchID)));
 }
Beispiel #7
0
 public List <MatchDTO> FindByResult(int Result)
 {
     return(this.FindByResultEntity(Result).Select(obj => MatchMapper.Map(obj)).ToList());
 }