Esempio n. 1
0
        private ProductFilterModel CreateFilter(string keyword, Guid? platformId, Guid? genreId, Guid? pegiId)
        {
            var filter = new ProductFilterModel();

            filter.SearchKeyword = keyword ?? string.Empty;
            filter.ProductSortType = ProductSortType.NameAscending;
            filter.ProductSortTypes = GeneralHelper.SelectListForEnum(typeof(ProductSortType));

            foreach (var platf in ProductManager.ProductCategories.OrderBy(c => c.Name))
            {
                filter.Platforms.Add(new SelectListItem
                {
                    Value = platf.Id.ToString(),
                    Text = platf.NameShort ?? platf.Name,
                    Selected = platf.Id == platformId
                });
            }
            foreach (var genre in ProductManager.Genres.OrderBy(g => g.Name))
            {
                filter.Genres.Add(new SelectListItem
                {
                    Value = genre.Id.ToString(),
                    Text = genre.Name,
                    Selected = genre.Id == genreId
                });
            }
            foreach (var pegi in PegiManager.PegiRates.OrderBy(p => p.SortIndex))
            {
                filter.PegiRatings.Add(new SelectListItem
                {
                    Value = pegi.Id.ToString(),
                    Text = pegi.Name,
                    Selected = pegi.Id == pegiId
                });
            }

            return filter;
        }
Esempio n. 2
0
        private ICollection<ProductListItem> SearchProducts(ProductFilterModel filter)
        {
            var products = new List<ProductListItem>();

            bool isSelectedAnyPlatform = filter.Platforms != null && filter.Platforms.Any(p => p.Selected);
            bool isSelectedAnyGenre = filter.Genres != null && filter.Genres.Any(p => p.Selected);
            bool isSelectedAnyPegi = filter.PegiRatings != null && filter.PegiRatings.Any(p => p.Selected);

            IEnumerable<SelectListItem> selectedPlatforms = null;
            IEnumerable<SelectListItem> selectedPegis = null;
            IEnumerable<SelectListItem> selectedGenres = null;

            if (isSelectedAnyGenre) { selectedGenres = filter.Genres.Where(p => p.Selected == true); }
            if (isSelectedAnyPegi) { selectedPegis = filter.PegiRatings.Where(p => p.Selected == true); }
            if (isSelectedAnyPlatform) { selectedPlatforms = filter.Platforms.Where(p => p.Selected == true); }

            foreach (var prod in ProductManager.Products.ToList())
            {
                if (!prod.IsDeleted && prod.Name.Contains(filter.SearchKeyword != null ? filter.SearchKeyword : string.Empty))
                {
                    if (isSelectedAnyGenre && !selectedGenres.Any(g =>
                        g.Value == prod.GenreId.ToString())) { continue; }
                    if (isSelectedAnyPlatform && !selectedPlatforms.Any(p =>
                        p.Value == prod.PlatformId.ToString())) { continue; }
                    if (isSelectedAnyPegi && !selectedPegis.Any(p =>
                        p.Value == prod.PegiRatingId.ToString())) { continue; }
                    products.Add(prod.ToListItem());
                }
            }

            return products.SortBy(filter.ProductSortType).ToList();
        }
Esempio n. 3
0
 public PartialViewResult Search(ProductFilterModel filter)
 {
     if (filter.ListDisplayMode)
     {
         return PartialView("_SearchProductsResult", SearchProducts(filter));
     }
     else
     {
         return PartialView("_SearchProductsResultTiles", SearchProducts(filter));
     }
 }