Beispiel #1
0
        public GamesTransferModel GetGamesByFilter(GamesFilterModel filterModel, PaginationModel paginationModel)
        {
            var container = new GameFilterContainer
            {
                Model = filterModel,
            };

            IPipeline <GameFilterContainer> pipeline = GetPipelineWithFilters();

            pipeline.ExecuteAll(container);
            Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions);

            IEnumerable <Game> games = _unitOfWork.GameRepository.GetMany(
                resultCondition, (int)paginationModel.PageCapacity, paginationModel.CurrentPage,
                container.SortCondition);
            var gameModels = Mapper.Map <IEnumerable <GameModel> >(games);

            paginationModel.ItemsNumber = _unitOfWork.GameRepository.GetCount(resultCondition);

            var transferModel = new GamesTransferModel
            {
                Games           = gameModels,
                PaginationModel = paginationModel,
            };

            return(transferModel);
        }
Beispiel #2
0
        private void SetUpModelForGamesFilter(GamesFilterModel model)
        {
            const int startMaxPrice = 1000000;

            model.SelectedGenresIds        = model.SelectedGenresIds ?? new int[] { };
            model.SelectedPlatformTypesIds = model.SelectedPlatformTypesIds ?? new int[] { };
            model.SelectedPublishersIds    = model.SelectedPublishersIds ?? new int[] { };

            if (model.MaxPrice == default(decimal))
            {
                model.MaxPrice = startMaxPrice;
            }

            model.PageInfo = model.PageInfo ?? new PageInfo
            {
                PageNumber = 1,
                PageSize   = PageSize.AllItems
            };

            model.PageInfo.TotalItems = _gameService.GetAmountOfGames();

            PageInfo pageInfo       = model.PageInfo;
            int      lastPageNumber = pageInfo.TotalItems / (int)pageInfo.PageSize;

            if (pageInfo.TotalItems % (int)pageInfo.PageSize != 0)
            {
                lastPageNumber++;
            }

            if (pageInfo.PageNumber > lastPageNumber)
            {
                model.PageInfo.PageNumber = lastPageNumber;
            }
        }
        public void ShouldReturnGamesByFilter()
        {
            var model = new GamesFilterModel
            {
                GameName = "GameName",
                MaxPrice = 10,
                MinPrice = 5,
                PageInfo = new PageInfo
                {
                    PageNumber = 1,
                    PageSize   = PageSize.TenItems,
                    TotalItems = 20
                },

                PublishingDatePeriod     = PublishingDatePeriod.AllTime,
                SelectedGenresIds        = new int[] { },
                SelectedPublishersIds    = new int[] { },
                SelectedPlatformTypesIds = new int[] { },
                SortingObject            = SortingObject.Default
            };

            _gameService
            .Setup(m => m.GetGames(It.IsAny <GamesFilterAttributes>()))
            .Returns(new List <GameDto>());

            _gamesController.Get(model);

            _gameService.Verify(m => m.GetGames(It.IsAny <GamesFilterAttributes>()), Times.AtLeastOnce);
        }
Beispiel #4
0
        public HttpResponseMessage Get([FromUri] GamesFilterModel model)
        {
            SetUpModelForGamesFilter(model);

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            GamesFilterAttributes attributes = GetAttributesFromModel(model);

            model.Games = _gameService.GetGames(attributes).ToList();

            return(Request.CreateResponse(HttpStatusCode.OK, model));
        }
Beispiel #5
0
        private GamesFilterAttributes GetAttributesFromModel(GamesFilterModel model)
        {
            var attributes = new GamesFilterAttributes
            {
                Genres                  = model.SelectedGenresIds.ToList(),
                PlatformTypes           = model.SelectedPlatformTypesIds.ToList(),
                Publishers              = model.SelectedPublishersIds.ToList(),
                SortingObject           = model.SortingObject,
                PublishingDatePeriod    = model.PublishingDatePeriod,
                MinPrice                = model.MinPrice,
                MaxPrice                = model.MaxPrice,
                GameNameSearchingString = model.GameName,
                PageInfo                = model.PageInfo
            };

            return(attributes);
        }