public virtual CarListModel PrepareListModel(CarSearchModel searchModel) { if (null == searchModel) { throw new ArgumentNullException(nameof(searchModel)); } var list = carService.GetAll( pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize, license: searchModel.SearchLicense, enabled: searchModel.SearchEnabled); var model = new CarListModel { Data = list.Select(x => { var modelItem = x.ToModel <CarModel>(); return(modelItem); }), Total = list.TotalCount }; return(model); }
//[MultipleButton(Name = "action", Argument = "Tourico")] public ActionResult GetCarDetails(string productId) { var prdId = Request.Form["productId"]; var sessionId = Request.Form["sessionId"]; var searchCarDetailInfo = new SearchCarInfo(); if (Session[sessionId] != null) { var cars = (SearchCarInfo[])Session[sessionId]; searchCarDetailInfo = cars.Select(x => x).First(p => p.productId == productId); } Session["SessionCarPrograms"] = searchCarDetailInfo; var resultInfo = new ResultsInfo(); CarServiceClient carSvc = new CarServiceClient(); var companyRules = carSvc.GetRulesAndRestrictions( new LoginHeader { UserName = "******", Password = "******", Culture = "en-US", Version = "1" }, searchCarDetailInfo.carCompanyId, out resultInfo); CarSearchModel carSearchModel = new CarSearchModel(); carSearchModel.searchCarInfo = searchCarDetailInfo; carSearchModel.companyrules = companyRules; return(View(carSearchModel)); }
public ActionResult SearchAvailableCarsByOptions(CarSearchViewModel carSearchViewModel) { CarSearchModel carSearchModel = Mapper.Map <CarSearchModel>(carSearchViewModel); var rentViewModel = carSearchViewModel.rentViewModel; var carDtos = carService.GetCarsByOptions(carSearchModel, rentViewModel.firstDayRent, rentViewModel.lastDayRent); var carViewModels = Mapper.Map <IEnumerable <CarViewModel> >(carDtos); // carSearchViewModel.CarViewModels = carViewModels; carSearchViewModel.BodyTypeDtos = carService.GetAllBodyTypeDtos(); carSearchViewModel.CarClassDtos = carService.GetAllCarClassDtos(); carSearchViewModel.FuelTypeDtos = carService.GetAllFuelTypeDtos(); carSearchViewModel.GearboxTypeDtos = carService.GetAllGearboxTypeDtos(); carSearchViewModel.ManufacturerDtos = carService.GetAllManufacturerDtos(); carSearchViewModel.TransmissionTypeDtos = carService.GetAllTransmissionTypeDtos(); var places = placeService.GetAll(); carSearchViewModel.rentViewModel.Locations = places; carSearchViewModel.rentViewModel.PickUpLocation = places .SingleOrDefault(p => p.Id == carSearchViewModel.rentViewModel.PickUpLocationId); carSearchViewModel.rentViewModel.ReturnLocation = places .SingleOrDefault(p => p.Id == carSearchViewModel.rentViewModel.ReturnLocationId); return(View("CarSearchView", carSearchViewModel)); }
static void Main(string[] args) { var cars = GetCars(); IQueryable <Car> results; // Search cars by year range var searchModel = new CarSearchModel { Owner = "John Doe", Year = 2015, OrderBy = CarSearchModel.OrderCarBy.Price }; var searchQuery = new SearchQuery <Car, CarSearchModel>(); searchQuery.Source = cars.AsQueryable(); results = searchQuery.Run(searchModel); // Show results if (results.Any()) { foreach (var item in results) { Console.WriteLine(item); } } }
public List <Car> FindCars(CarSearchModel searchModel) {//takes search model, makes instance of another class CarSearch, //and uses a method in the class to return a list of cars that //fit the search criteria var search = new CarSearch(); var list = search.SearchCars(searchModel).ToList(); return(list); }
public virtual IActionResult List(CarSearchModel searchModel) { if (!permissionService.Authorize(StandardPermissionProvider.ManageCars)) { return(AccessDeniedView()); } var model = carFactory.PrepareListModel(searchModel); return(Json(model)); }
public virtual CarSearchModel PrepareSearchModel(CarSearchModel searchModel) { if (null == searchModel) { throw new ArgumentNullException(nameof(searchModel)); } baseAdminModelFactory.PrepareEnabledOptions(searchModel.AvailableEnabledOptions); searchModel.SetGridPageSize(); return(searchModel); }
public List <Car> FoundCars(int?vin, string make, string model, int?yearFrom, int?yearTo, string color) {//creates instance of search model using search inputs (if any) CarSearchModel searchModel = new CarSearchModel { VIN = vin, Make = make, Model = model, YearFrom = yearFrom, YearTo = yearTo, Color = color }; return(FindCars(searchModel)); }
public async Task <IEnumerable <Car> > Search(CarSearchModel carSearch) { var carList = new List <Car>(); if (carSearch.GetType().GetProperties().All(c => c.GetValue(carSearch) == null)) { return(carList); } var cars = await GetAll(); carList.AddRange(cars .Where(x => carSearch.Make == null || x.Make.Contains(carSearch.Make, StringComparison.OrdinalIgnoreCase)) .Where(x => carSearch.Model == null || x.Model.Contains(carSearch.Model, StringComparison.OrdinalIgnoreCase)) .Where(x => carSearch.Year == null || x.Year == carSearch.Year) .Where(x => carSearch.Color == null || x.Color.Contains(carSearch.Color, StringComparison.OrdinalIgnoreCase))); return(carList); }
public ActionResult AdvancedQuery(CarSearchModel carSearchModel) { return(Json(_carService.AdvancedQueryCar(carSearchModel.Keyword))); }
public IEnumerable <CarDto> GetCarsByOptions(CarSearchModel carSearchModel, DateTime firstDayRent, DateTime lastDayRent) { IEnumerable <CarDto> cars = GetAvailableCarsForDates(firstDayRent, lastDayRent); if (carSearchModel.ManufacturerDtoId.HasValue) { cars = cars.Where(c => c.ManufacturerId == carSearchModel.ManufacturerDtoId.Value); } if (carSearchModel.GearboxTypeDtoId.HasValue) { cars = cars.Where(c => c.GearboxTypeId == carSearchModel.GearboxTypeDtoId.Value); } if (carSearchModel.FuelTypeDtoId.HasValue) { cars = cars.Where(c => c.FuelTypeId == carSearchModel.FuelTypeDtoId.Value); } if (carSearchModel.CarClassDtoId.HasValue) { cars = cars.Where(c => c.CarClassId == carSearchModel.CarClassDtoId.Value); } if (carSearchModel.BodyTypeDtoId.HasValue) { cars = cars.Where(c => c.BodyTypeId == carSearchModel.BodyTypeDtoId.Value); } if (carSearchModel.TransmissionTypeDtoId.HasValue) { cars = cars.Where(c => c.TransmissionTypeId == carSearchModel.TransmissionTypeDtoId.Value); } if (carSearchModel.MinPrice.HasValue) { cars = cars.Where(c => c.PricePerDay >= carSearchModel.MinPrice.Value); } if (carSearchModel.MaxPrice.HasValue) { cars = cars.Where(c => c.PricePerDay <= carSearchModel.MaxPrice.Value); } if (carSearchModel.WithAirConditioning.HasValue) { cars = cars.Where(c => c.WithAirConditioning == carSearchModel.WithAirConditioning.Value); } if (carSearchModel.NameAsc.HasValue) { if (carSearchModel.NameAsc.Value) { cars = cars.OrderBy(c => c.Name); } else { cars = cars.OrderByDescending(c => c.Name); } } if (carSearchModel.PriceAsc.HasValue) { if (carSearchModel.PriceAsc.Value) { cars = cars.OrderBy(c => c.PricePerDay); } else { cars = cars.OrderByDescending(c => c.PricePerDay); } } if (carSearchModel.ProductionYearAsc.HasValue) { if (carSearchModel.ProductionYearAsc.Value) { cars = cars.OrderBy(c => c.ProductionYear); } else { cars = cars.OrderByDescending(c => c.ProductionYear); } } return(cars); }
public ActionResult SearchResult(CarSearchModel model) { ViewBag.Shippers = this.Data.Shippers.All(); ViewBag.searchString = model.Description; // Get Cars model.Cars = _cars.All() .Where(x => (model.Description == null || x.Description.Contains(model.Description)) && (model.Shippers == null || x.ShipperId == model.Shippers)) .OrderBy(x => x.Year) .ToList(); // total records for paging model.TotalRecords = _cars.All() .Count(x => (model.Description == null || x.Description.Contains(model.Description)) && (model.Shippers == null || x.ShipperId == model.Shippers)); return View(model); }
public async Task <ActionResult> Search(CarSearchModel car) { var model = await _service.Search(car); return(View(model)); }
public ActionResult Index(CarSearchModel model) { if (this.ModelState.IsValid) { var theSetting = ConfigurationManager.AppSettings["ApiUriBase"]; var theEndpoint = theSetting += "Cars"; UriBuilder theEndpointUriBuilder = new UriBuilder(theEndpoint); IDictionary <string, string> query = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(model.CarColor)) { query["Color"] = model.CarColor; } if (!string.IsNullOrWhiteSpace(model.CarModel)) { query["Model"] = model.CarModel; } if (!string.IsNullOrWhiteSpace(model.CarMake)) { query["Make"] = model.CarMake; } if (model.CarYear.HasValue) { query["Year"] = model.CarYear.Value.ToString(); } foreach (var kvp in query) { theEndpointUriBuilder.Query = kvp.Key + "=" + Uri.EscapeDataString(kvp.Value); } var request = (HttpWebRequest)WebRequest.Create(theEndpointUriBuilder.Uri.ToString()); request.Method = "GET"; request.Accept = "application/json"; HttpWebResponse response = null; if (response.StatusCode == HttpStatusCode.OK) { try { response = (HttpWebResponse)request.GetResponse(); var responseStream = response.GetResponseStream(); string content; using (var reader = new StreamReader(responseStream)) { content = reader.ReadToEnd(); } var cars = JsonConvert.DeserializeObject <IEnumerable <Car> >(content); return(View("Results", cars)); } finally { response?.Dispose(); } } else { // TODO error reporting this.ModelState.AddModelError(string.Empty, "Http request failed " + response.StatusDescription); } } return(View(model)); }
public ActionResult Search(CarSearchModel search) { var result = _carService.Where(Mapper.Map <CarSearchQuery>(search)); return(PartialView("Partials/_Cars", Mapper.Map <CarResultViewModel>(result))); }
public async Task <IActionResult> Search([FromQuery] CarSearchModel model) { model.PickupLocation.Trim(); model.PickupLocation = model.PickupLocation.Replace(", ", ","); if (model.FromTime == null || model.FromTime == "null") { model.FromTime = "09:00"; } if (model.ToTime == null || model.ToTime == "null") { model.ToTime = "18:00"; } DateTime from = String2Date(model.FromDate, model.FromTime); DateTime toReturn = String2Date(model.ToDate, model.ToTime); DateTime to = toReturn; if (model.SameDrop == "false") { to = to.AddDays(2); } var branches = await dbContext.RentalAgencyBranches .Include(branch => branch.Location) .Include(branch => branch.Cars) .ThenInclude(car => car.Reserved) .ToListAsync(); List <RetCar> retValue = new List <RetCar>(); foreach (RentalAgencyBranch branch in branches) { if (model.PickupLocation.Contains(",")) { string[] pickupArray = model.PickupLocation.Split(','); if (pickupArray[0].ToLower() != branch.Location.Country.ToLower() || pickupArray[1].ToLower() != branch.Location.City.ToLower()) { continue; } } else if (model.PickupLocation.ToLower() != branch.Location.Country.ToLower() && model.PickupLocation.ToLower() != branch.Location.City.ToLower()) { continue; } foreach (Car car in branch.Cars) { bool reserved = false; foreach (Date date in car.Reserved) { if (date.DateReserved.Date >= from.Date && date.DateReserved.Date <= to.Date) { reserved = true; break; } } if (!reserved) { string[] dbImage = car.Image.Split('%'); byte[] image = await System.IO.File.ReadAllBytesAsync(dbImage[0]); car.Image = "data:image/" + dbImage[1] + ";base64," + Convert.ToBase64String(image); retValue.Add(new RetCar { Location = branch.Location, Car = car }); } } } return(Ok(retValue)); }