Esempio n. 1
0
        public ActionResult ByProductSubCategory(string id, string subId, string brand, string category, string device, string manufacturer)
        {
            var dataService = new ProductService(Session);
            var products = dataService.GetProductsBySubCategoryService(subId);
            var facetViewModel = new FacetViewModel {Name = subId, CategoryName = id};
            List<Product> filteredProducts = products;

            if (brand != null)
                filteredProducts = products.Where(x => x.BrandName.Name.Equals(brand)).ToList();
            if (category != null)
                filteredProducts = products.Where(x => x.ProductSubCategory.Name.Equals(category)).ToList();
            if (manufacturer != null)
                filteredProducts = products.Where(x => x.Manufacturer.Name.Equals(manufacturer)).ToList();
            facetViewModel.AddProducts(filteredProducts);

            foreach (var product in products)
            {
                var tempProd = product;
                if (!facetViewModel.ProductCategories.Any(c => c == tempProd.ProductSubCategory))
                {
                    facetViewModel.ProductCategories.Add(product.ProductSubCategory);
                }
                if (!facetViewModel.BrandNames.Any(c => c == tempProd.BrandName))
                {
                    facetViewModel.BrandNames.Add(product.BrandName);
                }
                if (!facetViewModel.Manufacturers.Any(c => c == tempProd.Manufacturer))
                {
                    facetViewModel.Manufacturers.Add(product.Manufacturer);
                }
                var tempDevices = tempProd.PhoneDevices.ToList();
                facetViewModel.AssociatedDevices = tempDevices.GroupBy(x => x.Name).Select(x => x.First()).ToList();
            }

            var filters = new StringBuilder();
            if (brand != null)
                filters.Append(" And Brand &rsaquo; " + brand);
            if (category != null)
                filters.Append(" And Category &rsaquo; " + category);
            facetViewModel.Name = subId;
            facetViewModel.FilterName = filters.ToString();

            var result = new ViewResult
            {
                ViewData = { Model = facetViewModel }
            };
            return result;
        }