Exemple #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);
        }
Exemple #2
0
        private void FillGameIndexViewModel(GameIndexViewModel gameIndexViewModel)
        {
            gameIndexViewModel        = gameIndexViewModel ?? new GameIndexViewModel();
            gameIndexViewModel.Filter = gameIndexViewModel.Filter ?? new GamesFilterViewModel();

            var filterModel = Mapper.Map <GamesFilterModel>(gameIndexViewModel.Filter);

            gameIndexViewModel.Pagination = gameIndexViewModel.Pagination ?? new PaginationViewModel();

            var paginationModel = Mapper.Map <PaginationModel>(gameIndexViewModel.Pagination);

            GamesTransferModel transferModel = _gameService.GetGamesByFilter(filterModel, paginationModel);

            gameIndexViewModel.Games      = Mapper.Map <IEnumerable <GameViewModel> >(transferModel.Games);
            gameIndexViewModel.Pagination = Mapper.Map <PaginationViewModel>(transferModel.PaginationModel);

            gameIndexViewModel.Filter.AvailablePlatformTypes =
                Mapper.Map <IEnumerable <PlatformTypeFilterViewModel> >(_platformTypeService.GetAll());
            gameIndexViewModel.Filter.AvailableGenres =
                Mapper.Map <IEnumerable <GenreFilterViewModel> >(_genreService.GetAll());
            gameIndexViewModel.Filter.AvailablePublishers =
                Mapper.Map <IEnumerable <PublisherFilterViewModel> >(_publisherService.GetAll());

            gameIndexViewModel.Filter.Genres        = gameIndexViewModel.Filter.Genres ?? new List <int>();
            gameIndexViewModel.Filter.PlatformTypes = gameIndexViewModel.Filter.PlatformTypes ?? new List <int>();
            gameIndexViewModel.Filter.Publishers    = gameIndexViewModel.Filter.Publishers ?? new List <int>();

            gameIndexViewModel.Filter.SelectedGenres = gameIndexViewModel.Filter.AvailableGenres
                                                       .Where(x => gameIndexViewModel.Filter.Genres.Contains(x.GenreId));
            gameIndexViewModel.Filter.SelectedPlatformTypes = gameIndexViewModel.Filter.AvailablePlatformTypes
                                                              .Where(x => gameIndexViewModel.Filter.PlatformTypes.Contains(x.PlatformTypeId));
            gameIndexViewModel.Filter.SelectedPublishers = gameIndexViewModel.Filter.AvailablePublishers
                                                           .Where(x => gameIndexViewModel.Filter.Publishers.Contains(x.PublisherId));
        }