Ejemplo n.º 1
0
        private List <RecordsTempData> GetCurrentData(FcDeHoekContext context, List <RecordsTempData> historicData, int idSeason = -1)
        {
            var allPlayers = PersonQueries.GetPlayers(context).ToList();

            foreach (var player in allPlayers)
            {
                var stats = PersonStatisticsQueries.GetByIdPerson(context, player.IdPerson).ToList();
                if (stats.Any())
                {
                    var tempData = new RecordsTempData
                    {
                        IdPlayer = player.IdPerson,
                        Player   = $"{player.Name} {player.FirstName}"
                    };

                    foreach (var stat in stats)
                    {
                        var game = GameQueries.GetById(context, stat.IdGame);
                        if (game != null && game.IdCompetition == eCompetitionType.League && (game.IdSeason == idSeason || idSeason == -1))
                        {
                            if ((stat.Goals != null && stat.Goals != 0) || stat.Assists != 0)
                            {
                                var playersHistoricData =
                                    historicData.FirstOrDefault(hd => hd.IdPlayer == player.IdPerson);
                                if (playersHistoricData != null)
                                {
                                    playersHistoricData.Assists += stat.Assists;
                                    playersHistoricData.Goals   += stat.Goals ?? 0;
                                }
                                else
                                {
                                    tempData.Assists += stat.Assists;
                                    tempData.Goals   += stat.Goals ?? 0;
                                    historicData.Add(tempData);
                                }
                            }
                        }
                    }
                }
            }

            return(historicData);
        }
Ejemplo n.º 2
0
        private StatisticsModel GetPlayerStats(FcDeHoekContext context, int idPerson)
        {
            var stats = new StatisticsModel
            {
                FriendlyGamesPlayed = 0,
                GoalsInFriendly     = 0,
                AssistsInFriendly   = 0,

                LeagueGamesPlayed = 0,
                GoalsInLeague     = 0,
                AssistsInLeague   = 0,

                CupGamesPlayed = 0,
                GoalsInCup     = 0,
                AssistsInCup   = 0,
            };

            var allPlayerStats  = PersonStatisticsQueries.GetByIdPerson(context, idPerson).ToList();
            var season          = SeasonQueries.GetCurrentSeason(context);
            var leagueGameIds   = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context, season.IdSeason, eCompetitionType.League).Select(lg => lg.IdGame).ToList();
            var friendlyGameIds = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context, season.IdSeason, eCompetitionType.Friendly).Select(lf => lf.IdGame).ToList();
            var cupGameIds      = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context, season.IdSeason, eCompetitionType.Cup).Select(lc => lc.IdGame).ToList();

            foreach (var playerStat in allPlayerStats)
            {
                if (leagueGameIds.Contains(playerStat.IdGame))
                {
                    if (playerStat.Played ?? false)
                    {
                        stats.LeagueGamesPlayed++;
                    }

                    stats.GoalsInLeague   += playerStat.Goals ?? 0;
                    stats.AssistsInLeague += playerStat.Assists;
                }

                if (friendlyGameIds.Contains(playerStat.IdGame))
                {
                    if (playerStat.Played ?? false)
                    {
                        stats.FriendlyGamesPlayed++;
                    }

                    stats.GoalsInFriendly   += playerStat.Goals ?? 0;
                    stats.AssistsInFriendly += playerStat.Assists;
                }

                if (cupGameIds.Contains(playerStat.IdGame))
                {
                    if (playerStat.Played ?? false)
                    {
                        stats.CupGamesPlayed++;
                    }

                    stats.GoalsInCup   += playerStat.Goals ?? 0;
                    stats.AssistsInCup += playerStat.Assists;
                }
            }

            stats.TotalGamesPlayed = stats.FriendlyGamesPlayed + stats.LeagueGamesPlayed + stats.CupGamesPlayed;
            stats.TotalGoalsScored = stats.GoalsInFriendly + stats.GoalsInLeague + stats.GoalsInCup;
            stats.TotalAssists     = stats.AssistsInFriendly + stats.AssistsInLeague + stats.AssistsInCup;

            return(stats);
        }