public List <TWSearchResultsVM> getTWSearchResultsVM(TWSearchVM model) { IQueryable <TravelWarrant> listQueryable = null; if (model.CarId == 0) { listQueryable = context.TravelWarrant .Where(x => x.StartTime >= model.SearchStartDate && x.StartTime <= model.SearchEndDate); } else if (model.CarId != 0) { listQueryable = context.TravelWarrant .Where(x => x.CarId == model.CarId) .Where(x => x.StartTime >= model.SearchStartDate && x.StartTime <= model.SearchEndDate); } List <TWSearchResultsVM> modelList = listQueryable .Select(x => new TWSearchResultsVM { TravelWarrantId = x.TravelWarrantId, StartTime = x.StartTime.ToShortDateString() + " " + x.StartTime.ToShortTimeString(), EndTime = x.EndTime.ToShortDateString() + " " + x.EndTime.ToShortTimeString(), StartLocation = x.StartLocation, EndLocation = x.EndLocation, NumberOfPassengers = x.NumberOfPassengers }).ToList(); return(modelList); }
public TWSearchVM getTWSearchVM() { TWSearchVM model = new TWSearchVM { carList = context.Car.Select(x => new SelectListItem { Value = x.CarId.ToString(), Text = x.CarModel.CarBrand.Name + " " + x.CarModel.Name + " | " + x.ChassisNumber }).ToList(), SearchEndDate = DateTime.Now, SearchStartDate = DateTime.Now }; model.carList.Add(new SelectListItem { Value = "0", Text = "None" }); return(model); }
public IActionResult SearchResults(TWSearchVM model) { List <TWSearchResultsVM> modelList = travelWarrantService.getTWSearchResultsVM(model); return(PartialView("SearchResults", modelList)); }
public IActionResult Search() { TWSearchVM model = travelWarrantService.getTWSearchVM(); return(View(model)); }