public async Task <ICollection <UpdatedPlayerDto> > GetPlayersInClubNewStatsAsync(int clubId) { var players = new List <UpdatedPlayerDto>(); var club = this.clubRepo.AllAsNoTracking().Where(x => x.Id == clubId).FirstOrDefault(); var clubSquadPage = await this.context.OpenAsync(club.PLSquadLink); var playersInClub = clubSquadPage.QuerySelectorAll(".squadList > li > a"); foreach (var player in playersInClub) { var playerInfoForUpdateDto = new UpdatedPlayerDto { PLOverviewLink = GlobalConstants.PremierLeagueLink .Replace("/clubs", string.Empty) + player.GetAttribute("href"), ClubId = clubId, SquadNumber = player.QuerySelector(".number")?.TextContent, }; playerInfoForUpdateDto.PremierLeagueRecordTotal = await this.GetPlayerStatsAsync(playerInfoForUpdateDto.PLTotalStatsLink); players.Add(playerInfoForUpdateDto); } return(players); }
private int GetPlayerPoints(PlayerForUpdateDto playerInDb, UpdatedPlayerDto updatedPlayer) { var points = 0; if (updatedPlayer.PremierLeagueRecordTotal.Appearances > playerInDb.PlayerStats.Appearances) { points += 2; } if (updatedPlayer.PremierLeagueRecordTotal.Wins > playerInDb.PlayerStats.Wins) { points += 3; } else if (updatedPlayer.PremierLeagueRecordTotal.Losses == playerInDb.PlayerStats.Losses) { points += 1; } if (updatedPlayer.PremierLeagueRecordTotal.CleanSheets != null && updatedPlayer.PremierLeagueRecordTotal.CleanSheets > playerInDb.PlayerStats.CleanSheets) { points += 2; } if (updatedPlayer.PremierLeagueRecordTotal.Goals > playerInDb.PlayerStats.Goals) { points += (updatedPlayer.PremierLeagueRecordTotal.Goals - playerInDb.PlayerStats.Goals) * 3; } if (updatedPlayer.PremierLeagueRecordTotal.Assists > playerInDb.PlayerStats.Assists) { points += (updatedPlayer.PremierLeagueRecordTotal.Assists - playerInDb.PlayerStats.Assists) * 2; } if (updatedPlayer.PremierLeagueRecordTotal.YellowCards > playerInDb.PlayerStats.YellowCards) { points -= (updatedPlayer.PremierLeagueRecordTotal.YellowCards - playerInDb.PlayerStats.YellowCards) * 1; } if (updatedPlayer.PremierLeagueRecordTotal.RedCards > playerInDb.PlayerStats.RedCards) { points -= (updatedPlayer.PremierLeagueRecordTotal.RedCards - playerInDb.PlayerStats.RedCards) * 2; } return(points); }
private async Task UpdatePlayerStatsAsync(PlayerForUpdateDto playerInDb, UpdatedPlayerDto updatedPlayer) { playerInDb.PlayerStats.Appearances = updatedPlayer.PremierLeagueRecordTotal.Appearances; playerInDb.PlayerStats.Wins = updatedPlayer.PremierLeagueRecordTotal.Wins; playerInDb.PlayerStats.Losses = updatedPlayer.PremierLeagueRecordTotal.Losses; playerInDb.PlayerStats.CleanSheets = updatedPlayer.PremierLeagueRecordTotal.CleanSheets; playerInDb.PlayerStats.GoalsConceded = updatedPlayer.PremierLeagueRecordTotal.GoalsConceded; playerInDb.PlayerStats.Clearences = updatedPlayer.PremierLeagueRecordTotal.Clearences; playerInDb.PlayerStats.Tackles = updatedPlayer.PremierLeagueRecordTotal.Tackles; playerInDb.PlayerStats.Goals = updatedPlayer.PremierLeagueRecordTotal.Goals; playerInDb.PlayerStats.Assists = updatedPlayer.PremierLeagueRecordTotal.Assists; playerInDb.PlayerStats.YellowCards = updatedPlayer.PremierLeagueRecordTotal.YellowCards; playerInDb.PlayerStats.RedCards = updatedPlayer.PremierLeagueRecordTotal.RedCards; playerInDb.PlayerStats.Shots = updatedPlayer.PremierLeagueRecordTotal.Shots; playerInDb.PlayerStats.ShotsOnTarget = updatedPlayer.PremierLeagueRecordTotal.ShotsOnTarget; playerInDb.PlayerStats.BigChanceCreated = updatedPlayer.PremierLeagueRecordTotal.BigChanceCreated; playerInDb.PlayerStats.Fouls = updatedPlayer.PremierLeagueRecordTotal.Fouls; playerInDb.PlayerStats.Passes = updatedPlayer.PremierLeagueRecordTotal.Passes; await this.statsService.UpdateStatsAsync(playerInDb.PlayerStats); }