コード例 #1
0
        public ActionResult InfinateScroll(int blockNumber)
        {
            List<ProductModel> productList = (List<ProductModel>)Session["ProductList"];

            int startIndex = (blockNumber - 1) * ECoupounConstants.BlockSize;
            productList = productList.Skip(startIndex).Take(ECoupounConstants.BlockSize).ToList();

            JsonModel jsonModel = new JsonModel();
            jsonModel.NoMoreData = productList.Count < ECoupounConstants.BlockSize;
            jsonModel.HTMLString = this.RenderPartialViewToString("_ProductPartial", productList);

            return Json(jsonModel);
        }
コード例 #2
0
        public ActionResult GetProductList(string sortBy, string manufacturer, string provider, string color, string size, string price, int blockNumber = 1)
        {
            int startIndex = (blockNumber - 1) * ECoupounConstants.BlockSize;
            List<ProductModel> productList = (List<ProductModel>)Session["ProductList"];
            List<ProductModel> filteredProducts = new List<ProductModel>();

            List<string> manufacturerList = null;
            List<string> providerList = null;
            List<string> colorList = null;
            List<string> priceList = null;
            List<double> sizeList = null;
            if (!string.IsNullOrWhiteSpace(manufacturer))
            {
                manufacturerList = manufacturer.Split(',').ToList();
                productList = productList.Where(p => manufacturerList.Contains(p.ManufacturerId.ToString())).ToList();
            }

            if (!string.IsNullOrWhiteSpace(provider))
            {
                providerList = provider.Split(',').ToList();
                productList = productList.Where(p => providerList.Contains(p.ProviderId.ToString())).ToList();
            }

            if (!string.IsNullOrWhiteSpace(sortBy) && sortBy == "low")
                productList = productList.OrderBy(x => x.SalePrice).ToList();
            else if (!string.IsNullOrWhiteSpace(sortBy) && sortBy == "high")
                productList = productList.OrderByDescending(x => x.SalePrice).ToList();

            if (!string.IsNullOrWhiteSpace(color))
            {
                colorList = color.Split(',').ToList();
                productList = productList.Where(p => colorList.Contains(p.Color)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(size))
            {
                sizeList = size.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToList();
                productList = productList.Where(p => sizeList.Contains(p.Size)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(price))
            {
                priceList = price.Split(',').ToList();
                foreach (string strPrice in priceList)
                {
                    string[] priceRange = strPrice.Split('-');
                    int fromRange = Convert.ToInt32(priceRange[0]);
                    int toRange = Convert.ToInt32(priceRange[1]);
                    List<ProductModel> productsInRange = productList.Where(p => p.SalePrice >= fromRange && p.SalePrice <= toRange).ToList();
                    filteredProducts.AddRange(productsInRange);
                }

                productList = filteredProducts.Skip(startIndex).Take(ECoupounConstants.BlockSize).ToList();
            }
            else
            {
                productList = productList.Skip(startIndex).Take(ECoupounConstants.BlockSize).ToList();
            }

            JsonModel jsonModel = new JsonModel();
            jsonModel.NoMoreData = productList.Count < ECoupounConstants.BlockSize;
            jsonModel.HTMLString = this.RenderPartialViewToString("_ProductPartial", productList);

            return Json(jsonModel);
        }