public ActionResult GetGames() { PaginationGames games = _gameService.Get(CurrentLanguageCode); FilterCriteria filter = new FilterCriteria() { Genres = _genreService.Get(CurrentLanguageCode), Platformtypes = _platformTypeService.Get(CurrentLanguageCode), Publishers = _publisherService.Get(CurrentLanguageCode) }; var filterViewModel = _mapper.Map <FilterCriteria, FilterCriteriaViewModel>(filter); var pageInfo = new PagingInfoViewModel() { CurrentPage = 1, ItemsPerPage = "10", TotalItems = games.Count }; TempData["games"] = games; return(View(new GamesAndFilterViewModel() { Filter = filterViewModel, Games = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games), PagingInfo = pageInfo })); }
public IHttpActionResult FilterGames(string contentType, FilterCriteriaViewModel filterViewModel, string size, int page = 1) { if (!ModelState.IsValid) { return(Content(HttpStatusCode.BadRequest, CreateError())); } FilterCriteria filters = _mapper.Map <FilterCriteriaViewModel, FilterCriteria>(filterViewModel); PaginationGames games = _gameService.FilterGames(filters, page, size, CurrentLanguage); filterViewModel.Genres = _mapper.Map <IEnumerable <Genre>, IList <GenreViewModel> >(_genreService.GetAllGenresAndMarkSelectedForFilter(filterViewModel.NameGenres, CurrentLanguage)); filterViewModel.PlatformTypes = _mapper.Map <IEnumerable <PlatformType>, IList <PlatformTypeViewModel> >(_platformTypeService.GetAllPlatformTypesAndMarkSelected(filterViewModel.NamePlatformTypes, CurrentLanguage)); filterViewModel.Publishers = _mapper.Map <IEnumerable <Publisher>, IList <PublisherViewModel> >(_publisherService.GetAllPublishersAndMarkSelected(filterViewModel.NamePublishers, CurrentLanguage)); var pageInfo = new PagingInfoViewModel { CurrentPage = page, ItemsPerPage = size, TotalItems = games.Count }; var result = Serialize(new GamesAndFilterViewModel() { Filter = filterViewModel, Games = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games), PagingInfo = pageInfo }, contentType); return(result); }
public IHttpActionResult GetGames(string contentType) { PaginationGames games = _gameService.Get(CurrentLanguage); FilterCriteria filter = new FilterCriteria { Genres = _genreService.Get(CurrentLanguage), Platformtypes = _platformTypeService.Get(CurrentLanguage), Publishers = _publisherService.Get(CurrentLanguage) }; var filterViewModel = _mapper.Map <FilterCriteria, FilterCriteriaViewModel>(filter); var pageInfo = new PagingInfoViewModel { CurrentPage = 1, ItemsPerPage = "10", TotalItems = games.Count }; var result = Serialize(new GamesAndFilterViewModel { Filter = filterViewModel, Games = _mapper.Map <IEnumerable <Game>, IList <GameViewModel> >(games.Games), PagingInfo = pageInfo }, contentType); return(result); }
public new PaginationGames Get(string cultureCode, params Expression <Func <Game, object> >[] includeProperties) { var games = new PaginationGames() { Count = _gameRepository.GetCountObject(x => true), Games = _gameRepository.Get(x => true, x => x.Id).ToList() }; foreach (var game in games.Games) { LocalizationProvider.Localize(game, cultureCode); } return(games); }
public PaginationGames FilterGames(FilterCriteria filters, int page, string size, string cultureCode) { _gamePipeline = new GamePipeline(); var filterExpression = _gamePipeline.ApplyFilters(filters); IEnumerable <Game> games; int?maxSize = size != "ALL" ? (int?)int.Parse(size) : null; switch (filters.SortCriteria) { case SortCriteria.ByPriceAsc: games = _gameRepository.Get(filterExpression, x => x.Price, true, page, maxSize); break; case SortCriteria.ByPriceDesc: games = _gameRepository.Get(filterExpression, x => x.Price, false, page, maxSize); break; case SortCriteria.MostCommented: games = _gameRepository.Get(filterExpression, x => x.Comments.Count(), false, page, maxSize); break; case SortCriteria.New: games = _gameRepository.Get(filterExpression, x => x.GameInfo.UploadDate, false, page, maxSize); break; case SortCriteria.MostPopular: games = _gameRepository.Get(filterExpression, x => x.GameInfo.CountOfViews, false, page, maxSize); break; default: games = _gameRepository.Get(filterExpression, x => x.Id, true, page, maxSize); break; } var filteredGames = new PaginationGames() { Count = _gameRepository.GetCountObject(filterExpression), Games = games.ToList() }; foreach (var game in filteredGames.Games) { LocalizationProvider.Localize(game, cultureCode); } return(filteredGames); }