BusinessLogic.Logic.Players.PlayerRetriever.GetAllPlayersWithNemesisInfo C# (CSharp) Метод

GetAllPlayersWithNemesisInfo() публичный Метод

public GetAllPlayersWithNemesisInfo ( int gamingGroupId, IDateRangeFilter dateRangeFilter = null ) : List
gamingGroupId int
dateRangeFilter IDateRangeFilter
Результат List
        public List<PlayerWithNemesis> GetAllPlayersWithNemesisInfo(int gamingGroupId, IDateRangeFilter dateRangeFilter = null)
        {
            if (dateRangeFilter == null)
            {
                dateRangeFilter = new BasicDateRangeFilter();
            }

            var playersWithNemesis = (from Player player in GetAllPlayersInGamingGroupQueryable(gamingGroupId)
                                          .Include(player => player.PlayerGameResults)
                                      select new PlayerWithNemesis
                                      {
                                          PlayerId = player.Id,
                                          ApplicationUserId = player.ApplicationUserId,
                                          PlayerName = player.Name,
                                          PlayerActive = player.Active,
                                          PlayerRegistered = !string.IsNullOrEmpty(player.ApplicationUserId),
                                          NemesisPlayerId = player.Nemesis == null ? (int?)null : player.Nemesis.NemesisPlayerId,
                                          NemesisPlayerName = player.Nemesis != null && player.Nemesis.NemesisPlayer != null
                                                                  ? player.Nemesis.NemesisPlayer.Name
                                                                  : null,
                                          PreviousNemesisPlayerId = player.PreviousNemesis == null ? (int?)null : player.PreviousNemesis.NemesisPlayerId,
                                          PreviousNemesisPlayerName = player.PreviousNemesis != null && player.PreviousNemesis.NemesisPlayer != null
                                                                          ? player.PreviousNemesis.NemesisPlayer.Name
                                                                          : null,
                                          GamingGroupId = player.GamingGroupId,
                                          GamesWon =
                                              player.PlayerGameResults.Where(
                                                                             x =>
                                                                             x.PlayedGame.DatePlayed >= dateRangeFilter.FromDate &&
                                                                             x.PlayedGame.DatePlayed <= dateRangeFilter.ToDate).Count(x => x.GameRank == 1),
                                          GamesLost =
                                              player.PlayerGameResults.Where(
                                                                             x =>
                                                                             x.PlayedGame.DatePlayed >= dateRangeFilter.FromDate &&
                                                                             x.PlayedGame.DatePlayed <= dateRangeFilter.ToDate).Count(x => x.GameRank > 1),
                                          //only get championed games where this player is the current champion
                                          TotalChampionedGames =
                                              player.ChampionedGames.Count(
                                                                           champion =>
                                                                           champion.GameDefinition.ChampionId != null &&
                                                                           champion.GameDefinition.ChampionId.Value == champion.Id)
                                      }
                                     ).ToList();

            PopulateNemePointsSummary(gamingGroupId, playersWithNemesis, dateRangeFilter);
            PopulateAchivements(playersWithNemesis);

            return playersWithNemesis//--deliberately ToList() first since Linq To Entities cannot support ordering by NemePointsSummary.TotalPoints
                                      .OrderByDescending(x => x.PlayerActive)
                                      .ThenByDescending(pwn => pwn.NemePointsSummary?.TotalPoints ?? 0)
                                      .ThenByDescending(pwn => pwn.GamesWon)
                                      .ThenBy(pwn => pwn.PlayerName)
                                      .ToList();
        }