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

            var matches = await matchesApiClient.GetAllMatches();

            return(MatchMapper.Map(matches, players));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id)
        {
            Match match = await _matchServices.GetMatchAsync(id);

            MatchViewModel mapMatch = MatchMapper.MapMatch(match);

            return(View("Edit", mapMatch));
        }
Ejemplo n.º 3
0
        // GET: Play
        public async Task <ActionResult> Index()
        {
            var currentMatch = DbContext.Matches.OrderBy(x => x.ExpireDate).FirstOrDefault(x => x.ExpireDate > DateTime.UtcNow);
            var userId       = await SignInManager.GetVerifiedUserIdAsync();

            var userAlredyPlayed = currentMatch == null ? false :
                                   DbContext.UserMatches.Any(x => x.MatchId == currentMatch.Id);

            return(View(MatchMapper.MapMatchModelToViewModel(currentMatch, message: "You have already played this match")));
        }
        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
            }));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create(MatchViewModel viewModel)
        {
            try
            {
                Match mapMatch = MatchMapper.MapMatch(viewModel);
                Match match    = await _matchServices.CreateMatchAsync(mapMatch);

                return(RedirectToAction("Index", new { id = match.MatchId }));
            }
            catch (GlobalException e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Index(int?currentPage, string search = null)
        {
            try
            {
                //string userId = FindCurrentUserId();

                int currPage   = currentPage ?? 1;
                int totalPages = await _matchServices.GetPageCount(10);

                IEnumerable <Match> allMatches = null;

                if (!string.IsNullOrEmpty(search))
                {
                    allMatches = await _matchServices.SearchMatch(search, currPage);
                }
                else
                {
                    allMatches = await _matchServices.GetAllMatchesAsync(currPage);
                }

                IEnumerable <MatchViewModel> matchListing = allMatches
                                                            .Select(m => MatchMapper.MapMatch(m));
                MatchIndexViewMode matchVM = MatchMapper.MapFromMatchIndex(matchListing,
                                                                           currPage, totalPages);

                #region For pagination buttons and distribution
                matchVM.CurrentPage = currPage;
                matchVM.TotalPages  = totalPages;

                if (totalPages > currPage)
                {
                    matchVM.NextPage = currPage + 1;
                }

                if (currPage > 1)
                {
                    matchVM.PreviousPage = currPage - 1;
                }
                #endregion

                return(View(matchVM));
            }
            catch (GlobalException e)
            {
                return(BadRequest(e.Message));
            }
        }
        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
            }));
        }
Ejemplo n.º 9
0
        public Response GetItem(string gameId)
        {
            RequestHelper.ValidateId(gameId);

            var gameInfo = GetGameInfo(gameId);

            if (gameInfo.CurrentTeam == null)
            {
                throw ResponseHelper.Get501NotImplemented("You must pick a team now, but this is not implemented yet...");
            }

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

            halDocument.AddLink("game-links", new Link(UriHelper.GetGameLinksUri(gameId)));

            // Add GameDateTime navigation.
            var gameDateTimeService = ServiceFactory.CreateGameDateTimeService(gameInfo);
            var now = gameDateTimeService.GetNow();
            var currentGameDateTimeResource = new GameDateTimeMapper(UriHelper).Map(now);

            halDocument.AddResource("rel:game-datetime-navigation", currentGameDateTimeResource);

            // Add my team.
            var teamResource = new TeamMapper(UriHelper).Map(gameInfo.CurrentTeam, TeamMapper.TeamName, TeamMapper.Rating, TeamMapper.RatingGoalkeeper, TeamMapper.RatingDefence, TeamMapper.RatingMidfield, TeamMapper.RatingAttack, TeamMapper.RatingPercentage);

            halDocument.AddResource("rel:my-team", teamResource);

            // Add season resource.
            var seasonService  = ServiceFactory.CreateSeasonService(gameInfo);
            var currentSeason  = seasonService.GetCurrentSeason();
            var seasonResource = new SeasonMapper(UriHelper).Map(currentSeason, SeasonMapper.SeasonShortName, SeasonMapper.SeasonLongName);

            bool endOfSeason  = seasonService.DetermineSeasonEnded(currentSeason.Id);
            bool endSeasonNow = currentSeason.EndDateTime == now.DateTime;

            if (endOfSeason && endSeasonNow)
            {
                var form = new Form("end-season")
                {
                    Action = UriHelper.GetSeasonUri(gameId, currentSeason.Id),
                    Method = "post",
                    Title  = "END SEASON!"
                };
                seasonResource.AddForm(form);
            }

            halDocument.AddResource("rel:current-season", seasonResource);

            // Add season team statistics.
            var statisticsService            = ServiceFactory.CreateStatisticsService(gameInfo);
            var seasonTeamStatistics         = statisticsService.GetSeasonTeamStatistics(currentSeason.Id, gameInfo.CurrentTeamId);
            var seasonTeamStatisticsResource = new SeasonTeamStatisticsMapper(UriHelper).Map(seasonTeamStatistics);

            halDocument.AddResource("rel:season-team-statistics", seasonTeamStatisticsResource);

            // Add next match day.
            var matchService  = ServiceFactory.CreateMatchService(gameInfo);
            var nextMatchDate = matchService.GetNextMatchDate(currentSeason.Id);

            if (nextMatchDate.HasValue)
            {
                var matchDayResourceFactory = new MatchDayResourceFactory(UriHelper, gameId, nextMatchDate.Value);

                var matchDayResource = matchDayResourceFactory.Create();

                // Add a resource for the match of the current team.
                var matchForCurrentTeam = matchService.GetByMatchDayAndTeam(nextMatchDate.Value, gameInfo.CurrentTeamId);
                if (matchForCurrentTeam != null)
                {
                    var matchResource = new MatchMapper(UriHelper).Map(
                        matchForCurrentTeam,
                        MatchMapper.CompetitionName,
                        MatchMapper.CompetitionType,
                        MatchMapper.Date,
                        MatchMapper.Round);

                    var teamMapper = new TeamMapper(UriHelper);

                    var homeTeamResource = teamMapper.Map(matchForCurrentTeam.HomeTeam, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition);
                    matchResource.AddResource("home-team", homeTeamResource);

                    var awayTeamResource = teamMapper.Map(matchForCurrentTeam.AwayTeam, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition);
                    matchResource.AddResource("away-team", awayTeamResource);

                    matchResource.AddResource("your-opponent", gameInfo.CurrentTeam.Equals(matchForCurrentTeam.HomeTeam) ? awayTeamResource : homeTeamResource);

                    matchDayResource.AddResource("next-match", matchResource);
                }

                // Only add the play next match day form when the matches are right now.
                if (nextMatchDate.Value == now.DateTime)
                {
                    var playNextMatchDayForm = matchDayResourceFactory.GetForm();
                    matchDayResource.AddForm(playNextMatchDayForm);
                }

                halDocument.AddResource("rel:next-match-day", matchDayResource);
            }

            // Add league table.
            var leagueTableService  = ServiceFactory.CreateLeagueTableService(gameInfo);
            var leagueTable         = leagueTableService.GetBySeasonAndCompetition(currentSeason.Id, gameInfo.CurrentTeam.CurrentLeagueCompetitionId);
            var leagueTableResource = new LeagueTableMapper(UriHelper).Map(leagueTable);

            leagueTableResource.AddLink("leaguetables", new Link(UriHelper.GetSeasonLeagueTablesUri(gameId, currentSeason.Id))
            {
                Name = "all", Title = "All league tables"
            });

            halDocument.AddResource("rel:leaguetable", leagueTableResource);

            var response = GetResponse(halDocument);

            return(response);
        }
Ejemplo n.º 10
0
 public void Update(MatchDTO model)
 {
     this.UpdateEntity(MatchMapper.Unmapper(model));
 }
Ejemplo n.º 11
0
 public List <MatchDTO> List()
 {
     return(this.ListEntities().Select(obj => MatchMapper.Map(obj)).ToList());
 }
Ejemplo n.º 12
0
 public void Insert(MatchDTO _Match)
 {
     this.InsertEntity(MatchMapper.Unmapper(_Match));
 }
Ejemplo n.º 13
0
 public MatchDTO Get(int MatchID)
 {
     return(MatchMapper.Map(this.GetEntity(MatchID)));
 }
Ejemplo n.º 14
0
 public List <MatchDTO> FindByResult(int Result)
 {
     return(this.FindByResultEntity(Result).Select(obj => MatchMapper.Map(obj)).ToList());
 }