Example #1
0
        public ActionResult GetAllGames(FilterViewModel model, PageViewModel pageViewModel, SortTypes SortType = SortTypes.MostPopular)
        {
            FilterDTO filterDto = Mapper.Map<FilterViewModel, FilterDTO>(model);

            var filtersResult = _gameService.GetFiltredGame(
                filterDto,
                SortType,
                new PageInfoDTO()
                {
                    ItemsPerPage = (int)pageViewModel.ItemsPerPage, PageNumber = pageViewModel.pageNumber
                });

            var gameViewModel = GetGamesViewModel( filtersResult.Games, model );

            gameViewModel.TotalPagesNumber = filtersResult.PagesNumber;

            gameViewModel.CurrentPageNumber = pageViewModel.pageNumber;

            return View( gameViewModel );
        }
Example #2
0
 /// <summary>
 /// Check FilterViewModel on null
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 private bool IsNotNullFilterModel(FilterViewModel model)
 {
     return model.Publishers != null
         || model.DateFilterType != 0
         || model.From != 0.0m
         || !string.IsNullOrEmpty(model.Name)
         || model.To != 0.0m
         || model.PlatformTypes != null
         || model.Genres != null;
 }
Example #3
0
        /// <summary>
        /// Set selected field in GamesViewModel from FilterViewModel
        /// </summary>
        /// <param name="model">Model to set fields in</param>
        /// <param name="filters">FilterViewModel with filters data</param>
        /// <returns>GamesViewModel with setted some fields</returns>
        private GamesViewModel SetSelectedFilters( GamesViewModel model, FilterViewModel filters)
        {
            if (filters != null)
            {

                if (filters.Genres != null)
                {
                    foreach (var genre in model.Genres.Where(g => filters.Genres.Any(id => id.ToString() == g.Value)))
                        genre.Selected = true;
                }

                if (filters.PlatformTypes != null)
                    foreach (var platformType in model.PlatformTypes.Where(platformType => filters.PlatformTypes.Any(pt => pt.ToString() == platformType.Value)))
                        platformType.Selected = true;

                if (filters.Publishers != null)
                {
                    foreach (var publisher in model.Publishers.Where(p => filters.Publishers.Any(id => id.ToString() == p.Value)))
                        publisher.Selected = true;
                }

                if (!string.IsNullOrEmpty(filters.Name))
                {
                    model.Name = filters.Name;
                }

                if (filters.To != 0.0m)
                {
                    model.To = filters.ToString();
                }

                if (filters.From != 0.0m)
                {
                    model.From = filters.From.ToString();
                }

            }
            return model;
        }
Example #4
0
        /// <summary>
        /// Creates a GamesViewModel from filter data (if it exist) and a list of games.
        /// </summary>
        /// <param name="games">A list of games</param>
        /// <param name="filters">Filter data</param>
        /// <returns>GamesViewModel</returns>
        private GamesViewModel GetGamesViewModel( IEnumerable<GameDTO> games, FilterViewModel filters = null )
        {
            GamesViewModel model = new GamesViewModel()
            {
                Games = games.Select(Mapper.Map<GameDTO, GameDetailsViewModel>),

                Publishers = _publisherService.GetAll().Select(p => new SelectListItem() { Text = p.CompanyName, Value = p.PublisherId.ToString() }).ToList(),

                Genres = _genreService.GetAll().Select(g => new SelectListItem() { Value = g.GenreId.ToString(), Text = g.Name }).ToList(),

                PlatformTypes = _plarfotmTypeService.GetAll().Select(pt => new SelectListItem() { Value = pt.PlatformTypeId.ToString(), Text = pt.Name }).ToList(),

                TotalPagesNumber = 1,

                CurrentDateFilterType = DateFilterTypes.All,

                CurrentItemsPerPage = ItemsPerPage.Two,

                CurrentSortType = SortTypes.MostPopular,

                CurrentPageNumber = 1
            };

            model = SetSelectedFilters(model, filters);

            return model;
        }