Esempio n. 1
0
        //-------------------------------------- Contollers for ByManufactuer-----------------------------------------------------------
        public ActionResult ByManufacturer(string id, string brand, string category, string device)
        {
            var productService = new ProductService(Session);

            var products = productService.GetProductsByManufacturerService(id);
            var facetViewModel = new FacetViewModel();
            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();
            facetViewModel.AddProducts(filteredProducts);

            foreach (var product in products)
            {
                var tempProd = product;
                if (!facetViewModel.ProductCategories.Any(c => c == tempProd.ProductSubCategory))
                {
                    //if (!product.ProductSubCategory.Name.Equals(category))
                        facetViewModel.ProductCategories.Add(product.ProductSubCategory);
                }
                if (!facetViewModel.BrandNames.Any(c => c == tempProd.BrandName))
                {
                    //if (!product.BrandName.Name.Equals(brand))
                        facetViewModel.BrandNames.Add(product.BrandName);
                }

                var tempDevices = tempProd.PhoneDevices.ToList();

                //PhoneDevice prod1 = prod;
                //if (!tempDevices.Any(x => x == prod1))
                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 = id;
            facetViewModel.FilterName = filters.ToString();
            facetViewModel.ByManufacturer = true;

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