Esempio n. 1
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;
        }
Esempio n. 2
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;
        }