public List<PlayedGame> GetRecentGames(int numberOfGames, int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if(dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } List<PlayedGame> playedGames = dataContext.GetQueryable<PlayedGame>() .Where(game => game.GamingGroupId == gamingGroupId && game.DatePlayed >= dateRangeFilter.FromDate && game.DatePlayed <= dateRangeFilter.ToDate) .Include(playedGame => playedGame.GameDefinition.BoardGameGeekGameDefinition) .Include(playedGame => playedGame.GamingGroup) .Include(playedGame => playedGame.PlayerGameResults .Select(playerGameResult => playerGameResult.Player)) .OrderByDescending(orderBy => orderBy.DatePlayed) .ThenByDescending(orderBy => orderBy.DateCreated) .Take(numberOfGames) .ToList(); //TODO this seems ridiculous but I can't see how to order a related entity in Entity Framework :( foreach (PlayedGame playedGame in playedGames) { playedGame.PlayerGameResults = playedGame.PlayerGameResults.OrderBy(orderBy => orderBy.GameRank).ToList(); } return playedGames; }
public GamingGroupFilter(IDateRangeFilter dateRangeFilter = null) { if(dateRangeFilter == null) { DateRangeFilter = new BasicDateRangeFilter(); }else { DateRangeFilter = dateRangeFilter; } }
public GamingGroupFilter(IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { DateRangeFilter = new BasicDateRangeFilter(); } else { DateRangeFilter = dateRangeFilter; } }
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(); }
public GamingGroupFilter(int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { GamingGroupId = gamingGroupId; if (dateRangeFilter == null) { DateRangeFilter = new BasicDateRangeFilter(); } else { DateRangeFilter = dateRangeFilter; } }
internal virtual GamingGroupSummary GetGamingGroupSummary(int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } else { dateRangeFilter.FromDate = dateRangeFilter.FromDate; dateRangeFilter.ToDate = dateRangeFilter.ToDate; } var filter = new GamingGroupFilter(gamingGroupId, dateRangeFilter); return(_gamingGroupRetriever.GetGamingGroupDetails(filter)); }
internal virtual GamingGroupSummary GetGamingGroupSummary(int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } else { dateRangeFilter.FromDate = dateRangeFilter.FromDate; dateRangeFilter.ToDate = dateRangeFilter.ToDate; } var filter = new GamingGroupFilter(dateRangeFilter) { NumberOfRecentGamesToShow = MAX_NUMBER_OF_RECENT_GAMES, GamingGroupId = gamingGroupId }; return(gamingGroupRetriever.GetGamingGroupDetails(filter)); }
public static Sql FilterByDateRange(this Sql sql, string columnName, IDateRangeFilter filter, DateRangeAdjustment rangeAdjustment = DateRangeAdjustment.None) { if (filter == null) { return(sql); } if (filter.DateFrom.HasValue && filter.DateTo.HasValue) { return(sql.Where($"{columnName} BETWEEN @0 AND @1", GetDateFromValue(filter.DateFrom, rangeAdjustment), GetDateToValue(filter.DateTo, rangeAdjustment))); } if (filter.DateFrom.HasValue) { sql = sql.Where($"{columnName} >= @0", GetDateFromValue(filter.DateFrom, rangeAdjustment)); } if (filter.DateTo.HasValue) { sql = sql.Where($"{columnName} <= @0", GetDateToValue(filter.DateTo, rangeAdjustment)); } return(sql); }
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.NemesisPlayerId, NemesisPlayerName = player.Nemesis.NemesisPlayer.Name, PreviousNemesisPlayerId = player.PreviousNemesis.NemesisPlayerId, PreviousNemesisPlayerName = player.PreviousNemesis.NemesisPlayer.Name, 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()); }
internal virtual void PopulateNemePointsSummary(int gamingGroupId, List <PlayerWithNemesis> playersWithNemesis, IDateRangeFilter dateRangeFilter) { var nemePointsDictionary = (from playerGameResult in _dataContext.GetQueryable <PlayerGameResult>() where playerGameResult.PlayedGame.GamingGroupId == gamingGroupId && playerGameResult.PlayedGame.DatePlayed >= dateRangeFilter.FromDate && playerGameResult.PlayedGame.DatePlayed <= dateRangeFilter.ToDate group playerGameResult by playerGameResult.PlayerId into groupedResults select new { BasePoints = groupedResults.Sum(x => x.NemeStatsPointsAwarded), GameDurationBonusPoints = groupedResults.Sum(x => x.GameDurationBonusPoints), WeightBonusPoints = groupedResults.Sum(x => x.GameWeightBonusPoints), PlayerId = groupedResults.Key }).ToDictionary(key => key.PlayerId, value => new NemePointsSummary(value.BasePoints, value.GameDurationBonusPoints, value.WeightBonusPoints)); foreach (var player in playersWithNemesis) { player.NemePointsSummary = nemePointsDictionary.ContainsKey(player.PlayerId) ? nemePointsDictionary[player.PlayerId] : new NemePointsSummary(0, 0, 0); } }
public virtual IList <GameDefinitionSummary> GetAllGameDefinitions(int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } var returnValue = _dataContext.GetQueryable <GameDefinition>() .Where(gameDefinition => gameDefinition.GamingGroupId == gamingGroupId && gameDefinition.Active) .Select(gameDefinition => new GameDefinitionSummary { Active = gameDefinition.Active, BoardGameGeekGameDefinitionId = gameDefinition.BoardGameGeekGameDefinitionId, Name = gameDefinition.Name, Description = gameDefinition.Description, GamingGroupId = gameDefinition.GamingGroupId, Id = gameDefinition.Id, PlayedGames = gameDefinition.PlayedGames.Where( playedGame => playedGame.DatePlayed >= dateRangeFilter.FromDate && playedGame.DatePlayed <= dateRangeFilter.ToDate) .ToList(), Champion = gameDefinition.Champion, ChampionId = gameDefinition.ChampionId, PreviousChampion = gameDefinition.PreviousChampion, PreviousChampionId = gameDefinition.PreviousChampionId, DateCreated = gameDefinition.DateCreated }) .OrderBy(game => game.Name) .ToList(); AddPlayersToChampionData(returnValue); returnValue.ForEach(summary => { summary.Champion = summary.Champion ?? new NullChampion(); summary.PreviousChampion = summary.PreviousChampion ?? new NullChampion(); summary.TotalNumberOfGamesPlayed = summary.PlayedGames.Count; if (summary.BoardGameGeekGameDefinitionId.HasValue) { summary.BoardGameGeekInfo = _boardGameGeekGameDefinitionInfoRetriever.GetResults(summary.BoardGameGeekGameDefinitionId.Value); } }); return(returnValue); }
public List <PlayedGame> GetRecentGames(int numberOfGames, int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } List <PlayedGame> playedGames = dataContext.GetQueryable <PlayedGame>() .Where(game => game.GamingGroupId == gamingGroupId && game.DatePlayed >= dateRangeFilter.FromDate && game.DatePlayed <= dateRangeFilter.ToDate) .Include(playedGame => playedGame.GameDefinition.BoardGameGeekGameDefinition) .Include(playedGame => playedGame.GamingGroup) .Include(playedGame => playedGame.PlayerGameResults .Select(playerGameResult => playerGameResult.Player)) .OrderByDescending(orderBy => orderBy.DatePlayed) .ThenByDescending(orderBy => orderBy.DateCreated) .Take(numberOfGames) .ToList(); //TODO this seems ridiculous but I can't see how to order a related entity in Entity Framework :( foreach (PlayedGame playedGame in playedGames) { playedGame.PlayerGameResults = playedGame.PlayerGameResults.OrderBy(orderBy => orderBy.GameRank).ToList(); } return(playedGames); }
internal virtual GamingGroupSummary GetGamingGroupSummary(int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } else { dateRangeFilter.FromDate = dateRangeFilter.FromDate; dateRangeFilter.ToDate = dateRangeFilter.ToDate; } var filter = new GamingGroupFilter(dateRangeFilter) { NumberOfRecentGamesToShow = MAX_NUMBER_OF_RECENT_GAMES, GamingGroupId = gamingGroupId }; return gamingGroupRetriever.GetGamingGroupDetails(filter); }
internal virtual void PopulateNemePointsSummary(int gamingGroupId, List<PlayerWithNemesis> playersWithNemesis, IDateRangeFilter dateRangeFilter) { var nemePointsDictionary = (from playerGameResult in dataContext.GetQueryable<PlayerGameResult>() where playerGameResult.PlayedGame.GamingGroupId == gamingGroupId && playerGameResult.PlayedGame.DatePlayed >= dateRangeFilter.FromDate && playerGameResult.PlayedGame.DatePlayed <= dateRangeFilter.ToDate group playerGameResult by playerGameResult.PlayerId into groupedResults select new { BasePoints = groupedResults.Sum(x => x.NemeStatsPointsAwarded), GameDurationBonusPoints = groupedResults.Sum(x => x.GameDurationBonusPoints), WeightBonusPoints = groupedResults.Sum(x => x.GameWeightBonusPoints), PlayerId = groupedResults.Key }).ToDictionary(key => key.PlayerId, value => new NemePointsSummary(value.BasePoints, value.GameDurationBonusPoints, value.WeightBonusPoints)); foreach (var player in playersWithNemesis) { player.NemePointsSummary = nemePointsDictionary.ContainsKey(player.PlayerId) ? nemePointsDictionary[player.PlayerId] : new NemePointsSummary(0, 0, 0); } }
public virtual IList<GameDefinitionSummary> GetAllGameDefinitions(int gamingGroupId, IDateRangeFilter dateRangeFilter = null) { if (dateRangeFilter == null) { dateRangeFilter = new BasicDateRangeFilter(); } var returnValue = _dataContext.GetQueryable<GameDefinition>() .Where(gameDefinition => gameDefinition.GamingGroupId == gamingGroupId && gameDefinition.Active) .Select(gameDefinition => new GameDefinitionSummary { Active = gameDefinition.Active, BoardGameGeekGameDefinitionId = gameDefinition.BoardGameGeekGameDefinitionId, Name = gameDefinition.Name, Description = gameDefinition.Description, GamingGroupId = gameDefinition.GamingGroupId, Id = gameDefinition.Id, PlayedGames = gameDefinition.PlayedGames.Where( playedGame => playedGame.DatePlayed >= dateRangeFilter.FromDate && playedGame.DatePlayed <= dateRangeFilter.ToDate) .ToList(), Champion = gameDefinition.Champion, ChampionId = gameDefinition.ChampionId, PreviousChampion = gameDefinition.PreviousChampion, PreviousChampionId = gameDefinition.PreviousChampionId, DateCreated = gameDefinition.DateCreated }) .OrderBy(game => game.Name) .ToList(); AddPlayersToChampionData(returnValue); returnValue.ForEach(summary => { summary.Champion = summary.Champion ?? new NullChampion(); summary.PreviousChampion = summary.PreviousChampion ?? new NullChampion(); summary.TotalNumberOfGamesPlayed = summary.PlayedGames.Count; if (summary.BoardGameGeekGameDefinitionId.HasValue) { summary.BoardGameGeekInfo = _boardGameGeekGameDefinitionInfoRetriever.GetResults(summary.BoardGameGeekGameDefinitionId.Value); } }); return returnValue; }