public ActionResult AddVehicle(DetailsVM addVehicle) { if (addVehicle.Vehicle.Year < 2000 || addVehicle.Vehicle.Year > 2021) { ModelState.AddModelError("Vehicle.Year", "Please enter a year between 2000 and 2021."); } if (addVehicle.Vehicle.MSRP < 0) { ModelState.AddModelError("Vehicle.MSRP", "MSRP must be a positive number."); } if (addVehicle.Vehicle.SalePrice < 0) { ModelState.AddModelError("Vehicle.SalePrice", "SalePrice must be a positive number."); } if (addVehicle.Vehicle.MSRP < addVehicle.Vehicle.SalePrice) { ModelState.AddModelError("Vehicle.MSRP", "SalePrice must be lower than MSRP."); } if (ModelState.IsValid) { addVehicle.Vehicle.Picture = "placeholder.png"; VehicleRepositoryFactory.GetVehicleRepository().Add(addVehicle.Vehicle); return(RedirectToAction("EditVehicle", new { vinNumber = addVehicle.Vehicle.VinNumber })); } else { var viewModel = addVehicle; viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); } }
public ActionResult Models() { var viewModel = new AddModel(); viewModel.AdminMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.AdminModels = ModelRepositoryFactory.GetModelRepository().GetModels(); return(View(viewModel)); }
public IHttpActionResult GetMakeDetails() { var repo = MakeRepositoryFactory.GetMakeRepository(); var MakeList = repo.GetMakeDetails(); return(Ok(MakeList)); }
public List <string> GetModelsByMake(string makeName) { var makeRepo = MakeRepositoryFactory.GetMakeRepository(); var makeId = makeRepo.GetMakeIdByName(makeName); return(modelList.Where(m => m.MakeId == makeId).Select(mo => mo.ModelName).ToList()); }
public ActionResult Purchase(SaleVM sold) { var details = new DetailsVM(); details.Vehicle = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(sold.Sale.VinNumber); details.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); details.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); details.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); details.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); details.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); sold.Details = details; if (sold.Sale.Phone == null && sold.Sale.Email == null) { ModelState.AddModelError("", "You must enter a phone number or an email address."); } if (sold.Sale.Zipcode.Length > 5) { ModelState.AddModelError("", "Zipcode should only be 5 digits long, please."); } if (sold.Sale.PurchasePrice < ((sold.Details.Vehicle.MSRP * 95) * .01m)) { ModelState.AddModelError("", "Purchase price should not be lower than 95% vehicle MSRP, please recalculate."); } if (sold.Sale.PurchasePrice > sold.Details.Vehicle.MSRP) { ModelState.AddModelError("", "Purchase price should not be greater than MSRP, please recalculate."); } var repo = SaleRepositoryFactory.GetSaleRepository(); if (ModelState.IsValid) { sold.Sale.UserID = User.Identity.GetUserId(); sold.Sale.PurchaseDate = DateTime.Now; } var result = repo.Add(sold.Sale); if (result != null) { var vehicleToUpdate = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(sold.Sale.VinNumber); vehicleToUpdate.IsPurchased = true; vehicleToUpdate.IsFeatured = false; VehicleRepositoryFactory.GetVehicleRepository().Edit(vehicleToUpdate); return(View("Index")); } // assign sold.UserID to currently logged in user // assign sold.PurchaseDate to DateTime.Now // if saving the purchase is a success, update vehicle.IsPurchased to true and vehicle.IsFeatured to false; return(View()); }
public ActionResult AddVehicle() { var viewModel = new DetailsVM(); viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); }
public ActionResult Index() { var viewModel = new FeaturedVM(); viewModel.FeaturedVehicles = VehicleRepositoryFactory.GetVehicleRepository().GetFeaturedVehicles(); viewModel.Specials = SpecialRepositoryFactory.GetSpecialRepository().GetSpecials(); viewModel.FeaturedMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.FeaturedModels = ModelRepositoryFactory.GetModelRepository().GetModels(); return(View(viewModel)); }
public ActionResult EditVehicle(string vinNumber) { var viewModel = new DetailsVM(); viewModel.Vehicle = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(vinNumber); viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); }
public ActionResult Makes() { var viewModel = new AddMake(); viewModel.AdminMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); foreach (var make in viewModel.AdminMakes) { make.UserID = UserManager.FindById(make.UserID).Email; } return(View(viewModel)); }
public ActionResult Makes(Make make) { var repo = MakeRepositoryFactory.GetMakeRepository(); make.UserId = User.Identity.GetUserId(); make.DateAdded = DateTime.Today; repo.AddMake(make); var model = new Make(); return(View(model)); }
public ActionResult Makes(AddMake make) { if (ModelState.IsValid) { var addMake = new Make() { MakeID = make.MakeID, MakeName = make.MakeName, DateAdded = DateTime.Now, UserID = User.Identity.GetUserName() }; MakeRepositoryFactory.GetMakeRepository().AddMake(addMake); return(RedirectToAction("Makes", "Admin")); } else { return(View(make)); } }
public ActionResult Inventory() { var bodystyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); var colors = ColorRepositoryFactory.GetColorRepository().GetColors(); var makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); var models = ModelRepositoryFactory.GetModelRepository().GetModels(); var transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); var vehicles = VehicleRepositoryFactory.GetVehicleRepository().GetVehicles(); var vehiclesToReturn = new List <VehicleDisplayVM>(); foreach (var vehicle in vehicles) { var model = new VehicleDisplayVM(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); model.BodyStyle = bodystyles.FirstOrDefault(b => b.BodyStyleID == vehicle.BodyStyleID); model.ExteriorColor = colors.FirstOrDefault(c => c.ColorID == vehicle.ExteriorColor); model.InteriorColor = colors.FirstOrDefault(c => c.ColorID == vehicle.InteriorColor); model.Transmission = transmission.FirstOrDefault(t => t.TransmissionID == vehicle.TransmissionID); vehiclesToReturn.Add(model); } //vehiclesToReturn = vehiclesToReturn.OrderBy(vehicle => vehicle.Vehicle.Year).ThenBy(vehicle => vehicle.Make.MakeName).ThenBy(vehicle => vehicle.Model.ModelName).ToList(); var usedVehicles = vehiclesToReturn.Where(v => v.Vehicle.Mileage > 1000).ToList(); var newVehicles = vehiclesToReturn.Where(v => v.Vehicle.Mileage <= 1000).ToList(); List <InventoryReportVehicleGroup> usedVehicleGroupList = VehicleList(usedVehicles); List <InventoryReportVehicleGroup> newVehicleGroupList = VehicleList(newVehicles); InventoryReportViewModel viewModel = new InventoryReportViewModel() { NewVehicles = newVehicleGroupList, UsedVehicles = usedVehicleGroupList }; return(View(viewModel)); }
public ActionResult Purchase(string vinNumber) { var details = new DetailsVM(); details.Vehicle = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(vinNumber); details.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); details.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); details.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); details.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); details.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); var viewModel = new SaleVM(); viewModel.Sale = new GuildCars.Models.Tables.Sale(); viewModel.Sale.VinNumber = vinNumber; viewModel.Details = details; return(View(viewModel)); }
public ActionResult Models(AddModel model) { if (ModelState.IsValid) { var addModel = new Model() { MakeID = model.MakeID, ModelID = model.ModelID, ModelName = model.ModelName, DateAdded = DateTime.Now, UserID = User.Identity.GetUserName() }; ModelRepositoryFactory.GetModelRepository().AddModel(addModel); var viewModel = new AddModel(); viewModel.AdminMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.AdminModels = ModelRepositoryFactory.GetModelRepository().GetModels(); return(View(viewModel)); } else { return(View(model)); } }
public List <AddModelViewModel> GetAllModelDetails() { var list = new List <AddModelViewModel>(); var makeRepo = MakeRepositoryFactory.GetMakeRepository(); foreach (var model in modelList) { var addModelViewModel = new AddModelViewModel(); addModelViewModel.ModelName = model.ModelName; addModelViewModel.MakeName = makeRepo.GetMakeById(model.MakeId); addModelViewModel.MakeId = model.MakeId; addModelViewModel.UserEmail = "abc"; addModelViewModel.DateAdded = model.DateAdded; list.Add(addModelViewModel); } return(list); }
public IHttpActionResult SearchAdminVehicles(string searchTerm, decimal priceMin, decimal priceMax, int yearMin, int yearMax, int mileage) { var vehicleRepo = VehicleRepositoryFactory.GetVehicleRepository(); var bodystyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); var colors = ColorRepositoryFactory.GetColorRepository().GetColors(); var makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); var models = ModelRepositoryFactory.GetModelRepository().GetModels(); var transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); if (searchTerm == "chipmunk") { searchTerm = ""; } try { var vehicles = vehicleRepo.GetVehiclesBySearchParameters(searchTerm, priceMin, priceMax, yearMin, yearMax, mileage); var vehiclesToReturn = new List <VehicleDisplayVM>(); foreach (var vehicle in vehicles) { var model = new VehicleDisplayVM(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); model.BodyStyle = bodystyles.FirstOrDefault(b => b.BodyStyleID == vehicle.BodyStyleID); model.ExteriorColor = colors.FirstOrDefault(c => c.ColorID == vehicle.ExteriorColor); model.InteriorColor = colors.FirstOrDefault(c => c.ColorID == vehicle.InteriorColor); model.Transmission = transmission.FirstOrDefault(t => t.TransmissionID == vehicle.TransmissionID); vehiclesToReturn.Add(model); } vehiclesToReturn.RemoveAll(v => v.Vehicle.IsPurchased == true); return(Ok(vehiclesToReturn)); } catch { return(BadRequest()); } }
public ActionResult Models(AddModelViewModel addModelViewModel) { var repo = ModelRepositoryFactory.GetModelRepository(); var makeRepo = MakeRepositoryFactory.GetMakeRepository(); var vehicleModel = new Model() { ModelName = addModelViewModel.ModelName, MakeId = makeRepo.GetMakeIdByName(addModelViewModel.MakeName), UserId = User.Identity.GetUserId(), DateAdded = DateTime.Today }; repo.AddModel(vehicleModel); var viewModel = new AddModelViewModel(); return(View(viewModel)); }
public ActionResult EditVehicle(DetailsVM editVehicle) { if (editVehicle.Vehicle.Year < 2000 || editVehicle.Vehicle.Year > 2021) { ModelState.AddModelError("Vehicle.Year", "Please enter a year between 2000 and 2021."); } if (editVehicle.Vehicle.MSRP <= 0) { ModelState.AddModelError("Vehicle.MSRP", "MSRP must be greater than $0."); } if (editVehicle.Vehicle.SalePrice < 0) { ModelState.AddModelError("Vehicle.SalePrice", "SalePrice must be greater than $0."); } if (editVehicle.Vehicle.MSRP < editVehicle.Vehicle.SalePrice) { ModelState.AddModelError("Vehicle.MSRP", "SalePrice must be lower than MSRP."); } if (ModelState.IsValid) { editVehicle.Vehicle.Picture = "placeholder.png"; VehicleRepositoryFactory.GetVehicleRepository().Edit(editVehicle.Vehicle); return(RedirectToAction("Index", "Home")); } else { var viewModel = new DetailsVM(); viewModel.Vehicle = editVehicle.Vehicle; viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); } }
[TestCase("Ni", 0.00, 1000000.00, 2000, 2021, -1)] // used inventory test - searchTerm provided //[TestCase("Ni", 0.00, 9000.00, 2015, 2017, -1)] // used inventory test - searchTerm provided, priceMax set //[TestCase("", 0.00, 100000.00, 2000, 2021, -2)] // new inventory test - no search terms entered //[TestCase("", 0.00, 100000.00, 2020, 2021, -2)] // new inventory test - year min/max entered //[TestCase("", 9000.00, 9200.00, 2000, 2021, -1)] // new inventory test - price min/max entered //[TestCase("Ni", 0.00, 1000000.00, 2000, 2021, -1)] // new inventory test - searchTerm provided //[TestCase("Ni", 0.00, 9000.00, 2015, 2017, -1)] // new inventory test - searchTerm provided, priceMax set public void CanGetVehicleBySearchParameters(string searchTerm, decimal priceMin, decimal priceMax, int yearMin, int yearMax, int mileage) { var vehicles = VehicleRepositoryFactory.GetVehicleRepository().GetVehicles(); var makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); var models = ModelRepositoryFactory.GetModelRepository().GetModels(); // used vehicle search, no search terms entered if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -1) { vehicles = vehicles.Where(v => v.Mileage > 1000).OrderBy(v => v.MSRP).Take(20).ToList(); Assert.AreEqual(4, vehicles.Count()); } // new vehicle search, no search terms entered else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -2) { vehicles = vehicles.Where(v => v.Mileage < 1000).OrderBy(v => v.MSRP).Take(20).ToList(); Assert.AreEqual(3, vehicles.Count()); } // admin or sales vehicle search, no search terms entered else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -3) { vehicles = vehicles.OrderBy(v => v.MSRP).Take(20).ToList(); Assert.AreEqual(7, vehicles.Count()); } else if (mileage == -1) // used vehicle, price min/max or year min/max was entered { vehicles = vehicles.Where(v => v.Mileage > 1000).ToList(); var vehiclesToReturn = new List <Vehicle>(); if (searchTerm != "") { foreach (var vehicle in vehicles) { var model = new VehicleWithNames(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm)) { vehiclesToReturn.Add(model.Vehicle); } } } if (vehiclesToReturn.Count() > 0) { vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin); vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax); vehiclesToReturn.RemoveAll(v => v.Year < yearMin); vehiclesToReturn.RemoveAll(v => v.Year > yearMax); Assert.AreEqual(2, vehiclesToReturn.Count()); } else { vehicles.RemoveAll(v => v.SalePrice < priceMin); vehicles.RemoveAll(v => v.SalePrice > priceMax); vehicles.RemoveAll(v => v.Year < yearMin); vehicles.RemoveAll(v => v.Year > yearMax); } Assert.AreEqual(2, vehicles.Count()); } else if (mileage == -2) { vehicles = vehicles.Where(v => v.Mileage < 1000).ToList(); Assert.AreEqual(3, vehicles.Count()); if (searchTerm != "") { foreach (var vehicle in vehicles) { var model = new VehicleWithNames(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm)) { vehicles.Add(model.Vehicle); } } } vehicles.RemoveAll(v => v.SalePrice < priceMin); vehicles.RemoveAll(v => v.SalePrice > priceMax); vehicles.RemoveAll(v => v.Year < yearMin); vehicles.RemoveAll(v => v.Year > yearMax); throw new NotImplementedException(); } }
public List <Vehicle> GetVehiclesBySearchParameters(string searchTerm, decimal priceMin, decimal priceMax, int yearMin, int yearMax, int mileage) { var makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); var models = ModelRepositoryFactory.GetModelRepository().GetModels(); // used vehicle search, no search terms entered if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -1) { return(_vehicles.Where(v => v.Mileage > 1000).OrderBy(v => v.MSRP).Take(20).ToList()); // 4 VEHICLES } // new vehicle search, no search terms entered else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -2) { return(_vehicles.Where(v => v.Mileage < 1000).OrderBy(v => v.MSRP).Take(20).ToList()); // 3 VEHICLES } // admin or sales vehicle search, no search terms entered else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -3) { return(_vehicles.OrderBy(v => v.MSRP).Take(20).ToList()); // 7 VEHICLES } else if (mileage == -1) // used vehicle, searchTerm, price min/max or year min/max was entered { List <Vehicle> vehicles = _vehicles.Where(v => v.Mileage > 1000).ToList(); var vehiclesToReturn = new List <Vehicle>(); if (searchTerm != "") { foreach (var vehicle in vehicles) { var model = new VehicleWithNames(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm)) { vehiclesToReturn.Add(model.Vehicle); } } } if (vehiclesToReturn.Count() > 0) { vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin); vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax); vehiclesToReturn.RemoveAll(v => v.Year < yearMin); vehiclesToReturn.RemoveAll(v => v.Year > yearMax); return(vehiclesToReturn); } else { vehicles.RemoveAll(v => v.SalePrice < priceMin); vehicles.RemoveAll(v => v.SalePrice > priceMax); vehicles.RemoveAll(v => v.Year < yearMin); vehicles.RemoveAll(v => v.Year > yearMax); } return(vehicles); } else if (mileage == -2) // new vehicle, searchterm, price min/max or year min/max selected { List <Vehicle> vehicles = _vehicles.Where(v => v.Mileage < 1000).ToList(); var vehiclesToReturn = new List <Vehicle>(); if (searchTerm != "") { foreach (var vehicle in vehicles) { var model = new VehicleWithNames(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm)) { vehiclesToReturn.Add(model.Vehicle); } } } if (vehiclesToReturn.Count() > 0) { vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin); vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax); vehiclesToReturn.RemoveAll(v => v.Year < yearMin); vehiclesToReturn.RemoveAll(v => v.Year > yearMax); return(vehiclesToReturn); } else { vehicles.RemoveAll(v => v.SalePrice < priceMin); vehicles.RemoveAll(v => v.SalePrice > priceMax); vehicles.RemoveAll(v => v.Year < yearMin); vehicles.RemoveAll(v => v.Year > yearMax); } return(vehicles); } else { List <Vehicle> vehicles = _vehicles; var vehiclesToReturn = new List <Vehicle>(); if (searchTerm != "") { foreach (var vehicle in vehicles) { var model = new VehicleWithNames(); model.Vehicle = vehicle; model.Model = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID); model.Make = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID); if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm)) { vehiclesToReturn.Add(model.Vehicle); } } } if (vehiclesToReturn.Count() > 0) { vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin); vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax); vehiclesToReturn.RemoveAll(v => v.Year < yearMin); vehiclesToReturn.RemoveAll(v => v.Year > yearMax); return(vehiclesToReturn); } else { vehicles.RemoveAll(v => v.SalePrice < priceMin); vehicles.RemoveAll(v => v.SalePrice > priceMax); vehicles.RemoveAll(v => v.Year < yearMin); vehicles.RemoveAll(v => v.Year > yearMax); } return(vehicles); } }