コード例 #1
0
        public HomeListProductViewModel GetLstHomeProductByCataId(int CataId, int Num)
        {
            HomeListProductViewModel model = new HomeListProductViewModel();

            model.CataObj = this.GetObjClasscifiById(CataId);
            int[] tmpcate = this.GetlstClassifiByParentId(CataId).Select(s => s.ClassificationId).ToArray();
            if (tmpcate.Length >= 1)
            {
                model.lstProduct = this.GetlstProduct().Where(s => tmpcate.Contains(s.CategoryId.Value) &&
                                                              s.StateId != (int)EnumCore.StateType.da_xoa).OrderByDescending(s => s.ProductId).Take(Num).ToList();
            }
            else
            {
                model.lstProduct = this.GetlstProduct().Where(s => s.CategoryId == CataId &&
                                                              s.StateId != (int)EnumCore.StateType.da_xoa).OrderByDescending(s => s.ProductId).Take(Num).ToList();
            }

            return(model);
        }
コード例 #2
0
        public ViewResult ListProduct(int page = 1, int pageSize = 10, int category = -1)
        {
            HomeListProductViewModel model = new HomeListProductViewModel();

            model.Products = _mainRepository.Products
                             .Where(x => category == -1 || x.CategoryId == category)
                             .OrderByDescending(x => x.ProductId)
                             .Skip((page - 1) * pageSize)
                             .Take(pageSize)
                             .ToList();
            model.PagingInfo = new PagingInfo()
            {
                CurentPage = page,
                PageSize   = pageSize,
                TotalItems = _mainRepository.Products
                             .Where(x => category == -1 || x.CategoryId == category)
                             .Count()
            };
            model.Categories      = _mainRepository.Categories.ToList();
            model.CurrentCategory = category;
            return(View(model));
        }