Example #1
0
        public List <Game> Apply(List <Game> games)
        {
            IEnumerable <Game> filtered = new List <Game>(games);

            // filter by deck first if needed
            if (DeckId != null)
            {
                if (DeckId == Deck.None.Id)
                {
                    filtered = filtered.Where(g => g.Deck == null);
                }
                else
                {
                    filtered = filtered.Where(g => g.Deck != null && DeckId.Equals(g.Deck.Id));
                }
            }
            // player class filter (only useful if deck is null)
            if (!PlayerClass.Equals(PlayerClass.ALL))
            {
                filtered = filtered.Where(g => g.PlayerClass == PlayerClass);
            }
            // opponent class filter
            if (!OpponentClass.Equals(PlayerClass.ALL))
            {
                filtered = filtered.Where(g => g.OpponentClass == OpponentClass);
            }
            // format filter
            if (!Format.Equals(GameFormat.ANY))
            {
                filtered = filtered.Where(g => g.Format == Format);
            }
            // region filter
            if (!Region.Equals(Region.ALL))
            {
                filtered = filtered.Where(g => g.Region == Region);
            }
            // game mode filter
            if (!Mode.Equals(GameMode.ALL))
            {
                // if Ranked filter is on, also check for Rank range filter
                if (Mode.Equals(GameMode.RANKED))
                {
                    // ignore rank if its invalid or equal to the default range
                    if (RankIsValid(Rank) && (Rank.Item1 != RANK_LO || Rank.Item2 != RANK_HI))
                    {
                        filtered = filtered.Where(g => g.Mode == GameMode.RANKED &&
                                                  g.Rank <= Rank.Item1 && g.Rank > Rank.Item2);
                    }
                }
                else
                {
                    filtered = filtered.Where(g => g.Mode == Mode);
                }
            }
            // time filter
            var range = ConvertTimeFrameToRange(TimeFrame);

            filtered = filtered.Where(g => g.StartTime >= range.Start && g.EndTime <= range.End);

            return(filtered.ToList());
        }