示例#1
0
            public int GetHashCode(ProductWithFeatures obj)
            {
                string toHash = obj.Name;

                foreach (var feature in obj.Features)
                {
                    toHash += feature.GetHashCode();
                }

                return(toHash.GetHashCode());
            }
示例#2
0
        public ActionResult ProductPage(int productId)
        {
            // определяем список DescriptionFeatures
            var descFeatures = descriptionFeatureRepo.DescriptionFeatures
                               .Where(df => df.ProductId == productId) ?? new List <DescriptionFeature>();

            var model = new ProductWithFeatures
            {
                Product             = productRepo.Products.FirstOrDefault(p => p.ProductID == productId),
                ProductFeatures     = productFeatureRepo.ProductFeatures.Where(f => f.ProductId == productId).ToList(),
                DescriptionFeatures = descFeatures.ToList()
            };

            return(View(model));
        }
示例#3
0
        public ActionResult BoilerList(
            CatalogueViewModel model,
            string firm,
            string category,
            string linkName,
            int page      = 1,
            bool isAjax   = false,
            string filter = "default")
        {
            ViewBag.Category = category;
            ViewBag.Firm     = firm;
            ViewBag.IsAjax   = isAjax;
            ViewBag.Filter   = filter;
            ViewBag.LinkName = linkName;

            var products = productRepo.Products.ToList();

            model.Categories = products.Select(n => n.Category).ToList().Distinct();
            if (category != null)
            {
                model.Firms = products
                              .Where(f => f.Category == category)
                              .Select(n => n.Firm).ToList().Distinct();
            }
            else
            {
                model.Firms = products.Select(n => n.Firm).ToList().Distinct();
            }

            // тут получаем характеристики текущей категории
            var categories = categoryRepo.Categories.ToList();

            model.CategoryFeatures = new List <string>();
            if (categories.Any() && !string.IsNullOrEmpty(category))
            {
                var categoryId = categories
                                 .Where(c => c.Name == category)
                                 .Select(c => c.Id)
                                 .Single();

                var catFeatureIds = categoryFeatureRepo.CategoryFeatures
                                    .Where(cf => cf.CategoryId == categoryId)
                                    .Select(cf => cf.FeatureId)
                                    .ToList();
                model.CategoryFeatures = catFeatureIds.Join(productFeatureRepo.ProductFeatures,
                                                            p => p,
                                                            t => t.Id,
                                                            (p, t) => t.Name).ToList();
            }

            // feature ranges
            // получить минимальные и максимальные цены
            model.FeatureRanges = new List <FeatureRange>();
            model.FeatureRanges.Add(
                new FeatureRange
            {
                FeatureName = "Цена",
                From        = products.Min(p => p.Price),
                To          = products.Max(p => p.Price)
            }
                );

            // filter by category and firm
            products = FilterProductList(products, category, firm);
            var prodFeatures            = productFeatureRepo.ProductFeatures.ToList();
            var productWithFeaturesList = new List <ProductWithFeatures>();

            if (products.Any())
            {
                foreach (var item in products)
                {
                    var prodWithFeatures = new ProductWithFeatures
                    {
                        Product         = item,
                        ProductFeatures = prodFeatures.Where(f => f.ProductId == item.ProductID).ToList()
                    };
                    productWithFeaturesList.Add(prodWithFeatures);
                }

                productWithFeaturesList = OrderProductWithFeaturesList(productWithFeaturesList, linkName, filter);

                model.ProductList = new ProductListViewModel
                {
                    ProductWithFeaturesList = productWithFeaturesList
                                              .Skip((page - 1) * PageSize)
                                              .Take(PageSize),
                    PagingInfo = new PagingInfo
                    {
                        CurrentPage  = page,
                        ItemsPerPage = PageSize,
                        TotalItems   = productWithFeaturesList.Count()
                    }
                };
                return(PartialView("BoilerList", model));
            }
            else
            {
                return(PartialView("ErrorPage", "Список товаров не найден"));
            }
        }
示例#4
0
 public bool Equals(ProductWithFeatures x, ProductWithFeatures y)
 {
     return(x.Features.SequenceEqual(y.Features));
 }