Пример #1
0
 public IActionResult Search(SearchPackageViewModel vm, string location)
 {
     if (ModelState.IsValid)
     {
         vm.Packages = _repoPackage.Query(p => p.Location == location);
     }
     return(View(vm));
 }
Пример #2
0
        public IActionResult Search()
        {
            SearchPackageViewModel vm = new SearchPackageViewModel
            {
                Packages = _repoPackage.GetAll()
                           //Packages = _repoPackage.Query(p => p.Availability == true)
            };

            return(View(vm));
        }
Пример #3
0
        public IActionResult Search(string keyword, string location, string sortOrder)
        {
            string searchLocation          = "";
            IEnumerable <Package> packList = _packRepo.Query(p => p.IsActive == true);

            string searchKeyword = "";

            SearchPackageViewModel vm = new SearchPackageViewModel();

            if (!(string.IsNullOrEmpty(location) || location.Equals("All")))
            {
                searchLocation = location;
                packList       = packList.Where(p => p.Location.ToUpper().Contains(location.ToUpper()));
            }
            else
            {
                searchLocation = "All";
            }

            if (!string.IsNullOrEmpty(keyword))
            {
                string input = keyword.ToUpper();
                searchKeyword = keyword;
                packList      = packList.Where(pk => pk.Name.ToUpper().Contains(input) || pk.Description.ToUpper().Contains(input));
            }

            ViewData["LocationSortParm"] = string.IsNullOrEmpty(sortOrder) ? "location_desc" : "";
            ViewData["PriceSortParm"]    = sortOrder == "Price" ? "Price_desc" : "Price";

            switch (sortOrder)
            {
            case "location_desc":
                packList = packList.OrderByDescending(p => p.Location);
                break;

            case "Price":
                packList = packList.OrderBy(p => p.Price);
                break;

            case "Price_desc":
                packList = packList.OrderByDescending(p => p.Price);
                break;

            default:
                packList = packList.OrderBy(p => p.Location);
                break;
            }

            vm.SearchLocation = searchLocation;
            vm.Keyword        = searchKeyword;
            vm.Packages       = packList;
            vm.Total          = packList.Count();

            return(View(vm));
        }