Esempio n. 1
0
        public async Task <PlayersWithScoresDto> GetPlayerWithScores(int id)
        {
            var player = await _content.Players.FirstOrDefaultAsync(p => p.PlayerId == id);

            PlayersWithScoresDto dto = new PlayersWithScoresDto();

            dto.FirstName     = player.FirstName;
            dto.Id            = player.Id;
            dto.PlayerId      = player.PlayerId;
            dto.PositionOne   = player.PositionOne;
            dto.PositionTwo   = player.PositionTwo;
            dto.PositionThree = player.PositionThree;
            dto.Price         = player.Price;
            dto.Surname       = player.Surname;
            dto.Team          = player.Team;

            //  Now need to get the average
            dto.AverageScore = GetAverageScoreForPlayer(id);
            dto.TotalScore   = GetTotalScoreForPlayer(id);

            PlayerScores lastPS = _content.PlayerScores.OrderByDescending(x => x.GameDate).FirstOrDefault(p => p.PlayerId == player.PlayerId);

            if (lastPS != null)
            {
                dto.LastScore = lastPS.Score;
            }
            else
            {
                dto.LastScore = 0;
            }


            return(dto);
        }
Esempio n. 2
0
        public async Task <IEnumerable <PlayersWithScoresDto> > GetPlayers()
        {
            var players = await _content.Players.OrderByDescending(a => a.Price).ToListAsync();

            List <PlayersWithScoresDto> playersWithScore = new List <PlayersWithScoresDto>();

            // need to go through and get each last score for each player and then return the Dto
            foreach (var player in players)
            {
                PlayerScores lastPS       = _content.PlayerScores.OrderByDescending(x => x.GameDate).FirstOrDefault(p => p.PlayerId == player.PlayerId);
                int          totalScore   = this.GetTotalScoreForPlayer(player.PlayerId);
                int          averageScore = this.GetAverageScoreForPlayer(player.PlayerId);

                PlayersWithScoresDto newDto = new PlayersWithScoresDto();
                newDto.FirstName = player.FirstName;
                newDto.Id        = player.Id;

                if (lastPS == null)
                {
                    newDto.LastScore = 0;
                }
                else
                {
                    newDto.LastScore = lastPS.Score;
                }

                newDto.TotalScore    = totalScore;
                newDto.AverageScore  = averageScore;
                newDto.PlayerId      = player.PlayerId;
                newDto.PositionOne   = player.PositionOne;
                newDto.PositionThree = player.PositionThree;
                newDto.PositionTwo   = player.PositionTwo;
                newDto.Price         = player.Price;
                newDto.Surname       = player.Surname;
                newDto.Team          = player.Team;

                playersWithScore.Add(newDto);
            }

            return(playersWithScore);
        }
Esempio n. 3
0
        public async Task <IEnumerable <PlayersWithScoresDto> > GetSpecificPlayers(int pos)
        {
            var players = await _content.Players.OrderByDescending(a => a.Price).ToListAsync();

            List <PlayersWithScoresDto> filterPlayers = new List <PlayersWithScoresDto>();

            if (pos <= 5)
            {
                // need to filter returned players
                foreach (Player player in players)
                {
                    if (player.PositionOne == pos || player.PositionTwo == pos || player.PositionThree == pos)
                    {
                        PlayerScores ps = _content.PlayerScores.OrderByDescending(x => x.GameDate).FirstOrDefault(p => p.PlayerId == player.PlayerId);

                        PlayersWithScoresDto newDto = new PlayersWithScoresDto();
                        newDto.FirstName = player.FirstName;
                        newDto.Id        = player.Id;

                        if (ps == null)
                        {
                            newDto.LastScore = 0;
                        }
                        else
                        {
                            newDto.LastScore = ps.Score;
                        }

                        newDto.PlayerId      = player.PlayerId;
                        newDto.PositionOne   = player.PositionOne;
                        newDto.PositionThree = player.PositionThree;
                        newDto.PositionTwo   = player.PositionTwo;
                        newDto.Price         = player.Price;
                        newDto.Surname       = player.Surname;
                        newDto.Team          = player.Team;

                        filterPlayers.Add(newDto);
                    }
                }
            }
            else
            {
                // else return all
                foreach (Player player in players)
                {
                    PlayerScores ps = _content.PlayerScores.OrderByDescending(x => x.GameDate).FirstOrDefault(p => p.PlayerId == player.PlayerId);

                    PlayersWithScoresDto newDto = new PlayersWithScoresDto();
                    newDto.FirstName = player.FirstName;
                    newDto.Id        = player.Id;

                    if (ps == null)
                    {
                        newDto.LastScore = 0;
                    }
                    else
                    {
                        newDto.LastScore = ps.Score;
                    }

                    newDto.PlayerId      = player.PlayerId;
                    newDto.PositionOne   = player.PositionOne;
                    newDto.PositionThree = player.PositionThree;
                    newDto.PositionTwo   = player.PositionTwo;
                    newDto.Price         = player.Price;
                    newDto.Surname       = player.Surname;
                    newDto.Team          = player.Team;

                    filterPlayers.Add(newDto);
                }
            }
            return(filterPlayers);
        }