コード例 #1
0
        public IEnumerable <GameDto> GetGames(GamesFilterAttributes attributes)
        {
            if (attributes == null)
            {
                return(UnitOfWork.Games.GetAll().Select(g => g.ToDto()).ToList());
            }

            _pipeline.Register(_filterFactory.MakeSortedGamesFilter())
            .Register(_filterFactory.MakeGamesByPriceRangeFilter(attributes.MinPrice, attributes.MaxPrice))
            .Register(_filterFactory.MakeGamesByPublishingDateFilter(attributes.PublishingDatePeriod));

            if (attributes.Genres != null && attributes.Genres.Count > 0)
            {
                _pipeline.Register(_filterFactory.MakeGamesByGenresWithIdsFilter(attributes.Genres));
            }

            if (attributes.PlatformTypes != null && attributes.PlatformTypes.Count > 0)
            {
                _pipeline.Register(_filterFactory.MakeGamesByPlatformTypesWithIdsFilter(attributes.PlatformTypes));
            }

            if (attributes.Publishers != null && attributes.Publishers.Count > 0)
            {
                _pipeline.Register(_filterFactory.MakeGamesByPublishersWithIdsFilter(attributes.Publishers));
            }

            if (attributes.SortingObject != SortingObject.Default)
            {
                _pipeline.Register(_filterFactory.MakeGamesBySortingObjectFilter(attributes.SortingObject));
            }

            if (!string.IsNullOrEmpty(attributes.GameNameSearchingString))
            {
                _pipeline.Register(_filterFactory.MakeGamesByGameNameFilter(attributes.GameNameSearchingString));
            }

            if (attributes.PageInfo.PageSize != PageSize.AllItems)
            {
                _pipeline.Register(_filterFactory.MakeGamesPaginationFilter(attributes.PageInfo));
            }

            return(UnitOfWork.Games.Find(_pipeline)
                   .Select(g => g.ToDto()));
        }