public ActionResult ProdListPartial(string jsonData) { JObject obj2 = JObject.Parse(jsonData); int id = obj2.SelectToken("catId").Value<int>(); int num = obj2.SelectToken("page").Value<int>(); ProductListViewModel model2 = new ProductListViewModel { Products = (from x in _pRepository.Products where x.CategoryID == id orderby x.ID descending select x).Skip<Product>(((num - 1) * this.PageSize)).Take<Product>(this.PageSize) }; PagingInfo info = new PagingInfo { Service = "Product", CurrentPage = num, ItemsPerPage = this.PageSize, TotalItems = (from x in this._pRepository.Products where x.CategoryID == id select x).Count<Product>(), CatId = id }; model2.PagingInfo = info; ProductListViewModel model = model2; return PartialView(model); }
public ActionResult Products( string catFilter, string sizeFilter, string priceFilter, int page = 1, string searchedTerm = null) { ProductListViewModel vm = new ProductListViewModel(); List<Product> res1 = new List<Product>(); List<Product> res2 = new List<Product>(); List<Product> res3 = new List<Product>(); List<Product> finalQuery = new List<Product>(); string[] arr1 = null; string[] arr2 = null; string[] arr3 = null; var prods = _pRepository.Products.ToList(); if (searchedTerm != null || !string.IsNullOrWhiteSpace(searchedTerm)) { var items = prods .Where(x => x.ProductType.ToLower().Contains(searchedTerm) ); vm = new ProductListViewModel { Products = items .OrderBy(x => x.ID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { Service = "Product", CurrentPage = page, ItemsPerPage = PageSize, TotalItems = items.Count() } }; return PartialView(vm); } if (catFilter != null) { arr1 = catFilter.Split(','); } if (Request.QueryString["size"] != null || sizeFilter != null) { arr2 = sizeFilter.Split(','); } if (Request.QueryString["price"] != null || priceFilter != null) { arr3 = priceFilter.Split(','); } if (catFilter == null && sizeFilter == null && priceFilter == null) { vm = new ProductListViewModel { Products = _pRepository.Products .OrderBy(x => x.ID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { Service = "Product", CurrentPage = page, ItemsPerPage = PageSize, TotalItems = _pRepository.Products.Count() } }; return PartialView(vm); } finalQuery = FilterCatalogItems(arr1, arr2, arr3); vm = new ProductListViewModel { Products = finalQuery .OrderBy(x => x.ID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { Service = "Product", CurrentPage = page, ItemsPerPage = PageSize, TotalItems = finalQuery.Count() } }; return PartialView(vm); }
public ViewResult ProdList(int catId = 0, int page = 1, string credentialToken = null, string resetToken = null) { ViewBag.Test = Session["test"]; if (_conf.Options().SelectedIsOnlineID) { throw new HttpException(410, "Offline"); } ViewBag.Token = credentialToken; ViewBag.ResetToken = resetToken; ViewBag.CatID = catId == 0 && _pRepository.Products.Count() > 0 ? _catRep.Get().Where(x => x.Products.Count() > 0).First().ID : catId; ProductListViewModel vm = new ProductListViewModel { Products = _pRepository.Products .Where(x => x.CategoryID == catId) .OrderBy(x => x.ID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { Service = "Product", CurrentPage = page, ItemsPerPage = PageSize, TotalItems = _pRepository.Products.Where(x => x.CategoryID == catId).Count(), CatId = catId }, }; return View(vm); }