Пример #1
0
        public ActionResult Index()
        {
            ProductListModel model = new ProductListModel();
            ProductSearch productSearch = new ProductSearch();
            CateAttrSearch cateAttrSearch = new CateAttrSearch();
            productSearch.CateId = RequestHelper.AllInt("CateId");
            productSearch.Attr = RequestHelper.All("Attr");

            int pageSize =20 ;
            int pageIndex = RequestHelper.QueryInt("page");
            pageIndex = pageIndex <= 0 ? 0 : pageIndex - 1;

            //类别信息()
            List<Cate> allCateList = _cateService.GetList(0, 0);
            model.CateList = new List<Cate>();

            //获取1级分类
            model.ParentCateList = allCateList.Where(ac => ac.Depth == 1).ToList();

            if (productSearch.CateId > 0)
            {
                Cate cate = allCateList.SingleOrDefault(c => c.CateId == productSearch.CateId);

                if (cate != null)
                {
                    productSearch.Lid = cate.Lid;
                    productSearch.Rid = cate.Rid;

                    //获取分类路径
                    model.PathCateList = allCateList.Where(ac => ac.Lid <= cate.Lid && ac.Rid >= cate.Rid).ToList();

                    model.CateList = allCateList.Where(ac => ac.Lid > model.PathCateList[0].Lid && ac.Rid < model.PathCateList[0].Rid).ToList();

                    model.CateList = _cateService.ConvertCateListToTree(model.CateList);

                    if (cate.ChildCount==0)
                    {
                        //属性信息
                        cateAttrSearch.Lid = cate.Lid;
                        cateAttrSearch.Rid = cate.Rid;
                        model.CateAttrList = _cateAttrService.GetList(cateAttrSearch);
                    }
                }
            }

            model.ProductSearch = productSearch;
            model.ProductPage = _productService.GetList(productSearch, pageIndex, pageSize);

            return View(model);
        }
Пример #2
0
        public ActionResult Index()
        {
            ProductListModel model = new ProductListModel();
            ProductSearch productSearch = new ProductSearch();
            CateAttrSearch cateAttrSearch = new CateAttrSearch();
            productSearch.CateId = RequestHelper.AllInt("CateId");
            productSearch.Attr = RequestHelper.All("Attr");
            int pageSize = 30;
            int pageIndex = 0;

            //类别信息()
            List<Cate> allCateList = _cateService.GetList(0, 0);
            model.CateList = new List<List<Cate>>();

            if (productSearch.CateId > 0)
            {
                Cate cate = allCateList.SingleOrDefault(c => c.CateId == productSearch.CateId);

                if (cate != null)
                {
                    productSearch.Lid = cate.Lid;
                    productSearch.Rid = cate.Rid;

                    //获取分类路径
                    model.PathCateList = allCateList.Where(ac => ac.Lid <= cate.Lid && ac.Rid >= cate.Rid).ToList();

                    //获取1级分类
                    model.ParentCateList = allCateList.Where(ac => ac.Depth == 1).ToList();

                    //根据路径加载相应的兄弟的节点

                    //获取分类信息
                    //if (cate.Depth == 1)
                    //{
                    //    model.CateList = allCateList.Where(ac => ac.Lid > cate.Lid && ac.Rid < cate.Rid && ac.Depth == 2).ToList();
                    //}
                    //else if (cate.Depth == 2)
                    //{
                    //    model.CateList = allCateList.Where(ac => ac.Pid == cate.Pid && ac.Depth == 2).ToList();
                    //}

                    foreach (var pathCate in model.PathCateList)
                    {
                        if (pathCate.Depth == 1)
                        {
                            model.CateList.Add(allCateList.Where(ac => ac.Depth == 1).ToList());
                        }

                        if (pathCate.Depth != 2)
                        {
                            model.CateList.Add(allCateList.Where(ac => ac.Pid == pathCate.CateId && ac.Depth == pathCate.Depth+1).ToList());
                        }
                    }

                    if (cate.Depth == 2)
                    {
                        //属性信息
                        cateAttrSearch.Lid = cate.Lid;
                        cateAttrSearch.Rid = cate.Rid;
                        model.CateAttrList = _cateAttrService.GetList(cateAttrSearch);
                    }
                }
            }
            else
            {
                model.CateList.Add(allCateList.Where(ac => ac.Depth == 1).ToList());
            }

            model.ProductSearch = productSearch;
            model.ProductList = _productService.GetList(productSearch, pageIndex, pageSize).Items;

            return View(model);
        }
Пример #3
0
        public IPage<Product> GetList(ProductSearch search, int pageIndex, int pageSize)
        {
            var query = _productRepository.Table;

            //类别检索
            if (search.Lid > 0 && search.Rid > 0)
            {
                query = from p in query
                        join c in _cateRepository.Table on p.CateId equals c.CateId
                        where c.Lid >= search.Lid && c.Rid <= search.Rid
                        select p;
            }

            //属性检索
            if (!string.IsNullOrEmpty(search.Attr))
            {
                var attrList = search.Attr.Split(';');

                foreach (var attr in attrList)
                {
                    query = from p in query
                            where p.SaleAttr.Contains(attr)
                            select p;
                }
            }

            query = query.OrderByDescending(b => b.ProductId);
            return new Page<Product>(query, pageIndex, pageSize);
        }