public IActionResult CarInventory(CarInventoryViewModel civm) { //IF: If the user filters on the same property, grab vehicles with same property and new filter //ELSE: If the user selects a new property, get all filter values for that property civm.Vehicles = (string.Equals(civm.selectedVehiclePropery.FilterString, civm.PropertyFilter)) ? civm.Vehicles = _vehicleRepo.GetVehiclesByFilter(civm.selectedVehiclePropery, civm.SelectedFilter) : civm.Vehicles = _vehicleRepo.GetVehiclesByProperty(civm.selectedVehiclePropery); civm.PropertyFilter = civm.selectedVehiclePropery.FilterString; civm.VehicleFilters = GetVehicleFilters(civm.selectedVehiclePropery.FilterString); civm.VehicleProperties = _vehicleRepo.GetVehicleFilterProperties(); return(View(civm)); }
public IActionResult CarInventory(string filter) { string defaultPropertyFilterString = "ModelType";//Default to Model Type var vehicleProperty = new VehicleProperty { FilterString = defaultPropertyFilterString }; var filteredVehicles = _vehicleRepo.GetVehiclesByFilter(vehicleProperty, filter); var civm = new CarInventoryViewModel { Vehicles = filteredVehicles, VehicleProperties = _vehicleRepo.GetVehicleFilterProperties(), SelectedFilter = filter, VehicleFilters = GetVehicleFilters(filter), PropertyFilter = defaultPropertyFilterString }; return(View(civm)); }
public ActionResult Inventory() { CarInventoryViewModel inventoryViewModel = new CarInventoryViewModel(); CarMockRepository carMock = new CarMockRepository(); MakeMockRepo makeRepo = new MakeMockRepo(); ModelMockRepo modelRepo = new ModelMockRepo(); IEnumerable <Car> allCars = carMock.GetAllCars(); foreach (Car item in allCars) { item.Make = makeRepo.GetById(item.MakeId); item.Model = modelRepo.GetById(item.ModelId); } IEnumerable <Car> newVehicles = allCars.Where(v => v.Type == "New"); IEnumerable <Car> usedVehicles = allCars.Where(v => v.Type == "Used"); inventoryViewModel.UsedInventory = Inventory(usedVehicles); inventoryViewModel.NewInventory = Inventory(newVehicles); return(View(inventoryViewModel)); }