コード例 #1
0
        public IActionResult Search(TravelPackageSearchViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <TravelPackage> travelPackages = _travelPackageDataService
                                                      .GetAll().ToList();

                travelPackages = travelPackages.Where(tp => tp.Activated == true).ToList();

                if (!string.IsNullOrEmpty(vm.Location))
                {
                    travelPackages = travelPackages.Where(tp => tp.Location.ToLower() == vm.Location.ToLower()).ToList();
                }

                if (vm.Ordered)
                {
                    travelPackages = travelPackages.OrderBy(tp => tp.Price).ToList();
                }

                if (vm.MinPrice != null && vm.MaxPrice != null)
                {
                    travelPackages = travelPackages
                                     .Where(tp => tp.Price >= vm.MinPrice && tp.Price <= vm.MaxPrice)
                                     .ToList();
                }
                else if (vm.MinPrice != null && vm.MaxPrice == null)
                {
                    travelPackages = travelPackages
                                     .Where(tp => tp.Price >= vm.MinPrice)
                                     .ToList();
                }
                else if (vm.MinPrice == null && vm.MaxPrice != null)
                {
                    travelPackages = travelPackages
                                     .Where(tp => tp.Price <= vm.MaxPrice)
                                     .ToList();
                }

                vm.NumTravelPackages = travelPackages.Count;
                vm.TravelPackages    = travelPackages;

                return(View(vm));
            }

            return(View(vm));
        }
コード例 #2
0
        public IActionResult Search()
        {
            List <TravelPackage> travelPackages = _travelPackageDataService
                                                  .GetAll().ToList();

            travelPackages = travelPackages.Where(tp => tp.Activated == true).ToList();

            TravelPackageSearchViewModel vm = new TravelPackageSearchViewModel
            {
                Location          = null,
                MaxPrice          = null,
                MinPrice          = null,
                NumTravelPackages = travelPackages.Count,
                Ordered           = false,
                TravelPackages    = travelPackages
            };

            return(View(vm));
        }