public static string Make(FilterProductsViewModel vm) { if (vm == null) { return(""); } List <string> conditions = new List <string>(); if (!string.IsNullOrEmpty(vm.Code)) { conditions.Add($"code={Uri.EscapeDataString(vm.Code)}"); } if (!string.IsNullOrEmpty(vm.Name)) { conditions.Add($"name={Uri.EscapeDataString(vm.Name)}"); } if (vm.StartPrice > 0) { conditions.Add($"startPrice={vm.StartPrice}"); } if (vm.EndPrice > 0) { conditions.Add($"endPrice={vm.EndPrice}"); } var conditionString = string.Join("&", conditions); return(!string.IsNullOrEmpty(conditionString) ? "?" + conditionString : ""); }
//FilterProductsViewModel public ActionResult FilterProducts(string SearchTerm, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy, int?pageNo) { FilterProductsViewModel model = new FilterProductsViewModel(); model.Products = ProductsService.Instance.SearchProducts(SearchTerm, minimumPrice, maximumPrice, categoryID, sortBy, (pageNo.HasValue? pageNo.Value:0), 10); int totalCount = ProductsService.Instance.SearchProductsCount(SearchTerm, minimumPrice, maximumPrice, categoryID, sortBy); model.Pager = new Pager(totalCount, pageNo); return(PartialView(model)); }
public ActionResult FilterProducts(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryId, int?sortBy, int?pageNo) { FilterProductsViewModel model = new FilterProductsViewModel(); model.Products = productfunction.SearchProducts(searchTerm, minimumPrice, maximumPrice, categoryId, sortBy, pageNo.Value, 10); int totalCount = productfunction.ProductsCountPager(searchTerm, minimumPrice, maximumPrice, categoryId, sortBy); model.Pager = new Pager(totalCount, pageNo); return(PartialView(model)); }
public async Task <ActionResult> Filter(FilterProductsViewModel filterProductsViewModel) { var filterStr = ProductFactory.Make(filterProductsViewModel); // Save filter string in session to use when exporting excel HttpContext.Session.SetString("FilterStr", filterStr); ViewBag.filterText = !string.IsNullOrEmpty(filterStr) ? "Filtered products for " + filterStr.Replace("?", "").Replace("&", ",") : ""; return(View("Index", await _service.GetProductsByFilter(filterStr))); }
public ActionResult FilterProducts(string searchTerm, int?minPrice, int?maxPrice, int?CategoryId, int?sortBy, int?pageNo) { pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1; int totalItem = ProductService.Instance.SearchProductsCount(searchTerm, minPrice, maxPrice, CategoryId, sortBy); FilterProductsViewModel _model = new FilterProductsViewModel(); _model.Pager = new Pager(totalItem, pageNo); _model.Products = ProductService.Instance.SearchProducts(searchTerm, minPrice, maxPrice, CategoryId, sortBy, pageNo.Value, 10); return(PartialView(_model)); }
public ShopController(ProductService productService, ConfigrationService configrationService, CategoryService categoryService, ShopViewModel model, FilterProductsViewModel filterModel, CheckoutViewModel checkoutViewModel, JsonResult result, ShopService shopService) { _productService = productService; _configrationService = configrationService; _categoryService = categoryService; _model = model; _filterModel = filterModel; _shopService = shopService; _checkoutViewModel = checkoutViewModel; _result = result; }
public ActionResult FilterProducts(string searchTerm, int?minnimumPrice, int?maxnimumPrice, int?categoryID, int?sortBy, int?pageNo) { pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1; FilterProductsViewModel model = new FilterProductsViewModel(); model.Products = ProductService.Instance.SearchProducts(searchTerm, minnimumPrice, maxnimumPrice, categoryID, sortBy, pageNo.Value); var totalProducts = ProductService.Instance.SearchProductsCount(searchTerm, minnimumPrice, maxnimumPrice, categoryID, sortBy); int pageSize = int.Parse(ConfigrutionService.Instance.GetConfig("ShopPageSize").Value); model.Pager = new Pager(totalProducts, pageNo, pageSize); model.CategoryID = categoryID; model.searchTerm = searchTerm; model.sortBy = sortBy; return(PartialView(model)); }
public ActionResult FilterProduct(string searchTxt, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy, int?pageNo) { int pageSize = 9; FilterProductsViewModel model = new FilterProductsViewModel(); pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1; model.SortBy = sortBy; model.CategoryID = categoryID; int totalCount = ProductService.Instance.SearchProductCount(searchTxt, minimumPrice, maximumPrice, categoryID, sortBy); model.Products = ProductService.Instance.SearchProduct(searchTxt, minimumPrice, maximumPrice, categoryID, sortBy, pageNo.Value, pageSize); model.Pager = new Pager(totalCount, pageNo, pageSize); return(PartialView(model)); }
public ActionResult FilterProducts(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy, int?pageNo) { var pageSize = ConfigurationsService.Instance.ShopPageSize(); FilterProductsViewModel model = new FilterProductsViewModel(); pageNo = pageNo.HasValue ? pageNo > 0 ? pageNo.Value : 1 : 1; model.SearchTerm = searchTerm; model.SortBy = sortBy; model.CategoryID = categoryID; int totalCount = ProductsService.Instance.SearchProductsCount(searchTerm, minimumPrice, maximumPrice, categoryID, sortBy); model.Products = ProductsService.Instance.SearchProducts(searchTerm, minimumPrice, maximumPrice, categoryID, sortBy, pageNo.Value, pageSize); model.Pager = new Pager(totalCount, pageNo, pageSize); return(PartialView(model)); }
// List of products partial View // the View of this action will only include the list of products public ActionResult FilterProducts(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryId, int?pageNo, int?sortBy = 1) { pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1; // validate 'pageNo' value FilterProductsViewModel model = new FilterProductsViewModel { Products = ProductsService.Instance.SearchProducts(searchTerm, minimumPrice, maximumPrice, categoryId, sortBy, pageNo.Value, 10), SortBy = sortBy.Value, categoryId = categoryId, searchTerm = searchTerm }; int totalCount = ProductsService.Instance.SearchProductsCount(searchTerm, minimumPrice, maximumPrice, categoryId, sortBy); // get total count of search Products model.Pager = new Pager(totalCount, pageNo); // instantiate Pager return(PartialView(model)); }