public IHttpActionResult GetModelsByMake(string makeName) { var repo = CarModelsRepositoryFactory.GetRepository(); var model = repo.GetDetailsAll().Where(m => m.Make.ToLower() == makeName.ToLower()); return(Ok(model)); }
public ActionResult Models(ModelsVM modelsVM) { if (ModelState.IsValid) { var repo = CarModelsRepositoryFactory.GetRepository(); var model = new CarModel(); var make = new CarMake(); model.Name = modelsVM.ModelName; make.MakeId = modelsVM.MakeId; repo.Insert(model, make); return(RedirectToAction("Models")); } return(View("Models", modelsVM)); }
public ActionResult UpdateVehicle(int id) { var makesRepo = CarMakesRepositoryFactory.GetRepository(); var vehicleTypesRepo = VehicleTypesRepositoryFactory.GetRepository(); var bodyStylesRepo = BodyStylesRepositoryFactory.GetRepository(); var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository(); var colorsRepo = ColorsRepositoryFactory.GetRepository(); var interiorColorsRepo = InteriorColorsRepositoryFactory.GetRepository(); var vehiclesRepo = VehiclesRepositoryFactory.GetRepository(); var modelsRepo = CarModelsRepositoryFactory.GetRepository(); var viewModel = new UpdateVehicleVM(); viewModel.SetMakeItems(makesRepo.GetAll()); viewModel.SetVehicleTypeItems(vehicleTypesRepo.GetAll()); viewModel.SetBodyStyleItems(bodyStylesRepo.GetAll()); viewModel.SetTransmissionTypeItems(transmissionTypesRepo.GetAll()); viewModel.SetColorItems(colorsRepo.GetAll()); viewModel.SetInteriorColorItems(interiorColorsRepo.GetAll()); viewModel.SetMakeModelItems(modelsRepo.GetDetailsAll()); var vehicleToUpdate = vehiclesRepo.GetById(id); var modelToUpdate = modelsRepo.GetById(vehicleToUpdate.ModelId); var makeToUpdate = makesRepo.GetById(modelToUpdate.MakeId); viewModel.VehicleId = vehicleToUpdate.VehicleId; viewModel.VIN = vehicleToUpdate.VIN; viewModel.ModelName = modelToUpdate.Name; viewModel.MakeName = makeToUpdate.Name; viewModel.VehicleTypeId = vehicleToUpdate.VehicleTypeId; viewModel.BodyStyleId = vehicleToUpdate.BodyStyleId; viewModel.ModelYear = vehicleToUpdate.ModelYear; viewModel.TransmissionTypeId = vehicleToUpdate.TransmissionTypeId; viewModel.ColorId = vehicleToUpdate.ColorId; viewModel.InteriorColorId = vehicleToUpdate.InteriorColorId; viewModel.Mileage = vehicleToUpdate.Mileage; viewModel.MSRP = vehicleToUpdate.MSRP; viewModel.SalePrice = vehicleToUpdate.SalePrice; viewModel.Description = vehicleToUpdate.Description; viewModel.IsFeatured = vehicleToUpdate.IsFeatured; return(View(viewModel)); }
public ActionResult InsertCarModel(CarModelItemViewModel model) { CarModels carmodel = new CarModels(); var makeRepo = CarMakesRepositoryFactory.GetRepository(); var repo = CarModelsRepositoryFactory.GetRepository(); var carModels = makeRepo.GetAll(); var makeID = (from carmod in carModels where model.MakeName == carmod.MakeName select carmod.MakeID).FirstOrDefault(); carmodel.MakeID = makeID; carmodel.ModelName = model.ModelName; DateTime today = DateTime.Today; carmodel.DateAdded = today; carmodel.Email = User.Identity.Name; if (model.ModelName == null) { ModelState.AddModelError("ModelName", "Model name cannot be blank"); } if (model.MakeName == null) { ModelState.AddModelError("MakeName", "Make name cannot be blank"); } if (ModelState.IsValid) { var mRepo = CarMakesRepositoryFactory.GetRepository(); List <CarMakes> carMakes = mRepo.GetAll(); var carMakeNames = (from carmake in carMakes select carmake.MakeName).ToList(); model.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1); repo.Insert(carmodel); return(View("Models", model)); } else { var mRepo = CarMakesRepositoryFactory.GetRepository(); List <CarMakes> carMakes = mRepo.GetAll(); var carMakeNames = (from carmake in carMakes select carmake.MakeName).ToList(); model.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1); return(View("Models", model)); } }
public ActionResult UpdateVehicle(UpdateVehicleVM updateVehicleVM) { if (ModelState.IsValid) { var originalVehicle = VehiclesRepositoryFactory.GetRepository().GetDetailsById(updateVehicleVM.VehicleId); var vehicleToUpdate = new Vehicle(); var modelToUpdate = new CarModel(); var makeToUpdate = new CarMake(); var employeeId = int.Parse(User.Identity.GetEmployeeId()); vehicleToUpdate.EmployeeId = employeeId; var repo = VehiclesRepositoryFactory.GetRepository(); if (updateVehicleVM.File != null && updateVehicleVM.File.ContentLength > 0) { var newId = repo.GetAll().Max(v => v.VehicleId) + 1; var fileSplit = Path.GetFileName(updateVehicleVM.File.FileName).Split('.'); var fileExtension = fileSplit[fileSplit.Length - 1]; var fileName = "inventory-x-" + newId + "." + fileExtension; var path = Path.Combine(Server.MapPath("~/Images/"), fileName); updateVehicleVM.File.SaveAs(path); vehicleToUpdate.ImageFileName = fileName; } else { vehicleToUpdate.ImageFileName = originalVehicle.ImageFileName; } vehicleToUpdate.VehicleId = updateVehicleVM.VehicleId; vehicleToUpdate.VIN = updateVehicleVM.VIN; modelToUpdate.Name = updateVehicleVM.ModelName; makeToUpdate.Name = updateVehicleVM.MakeName; vehicleToUpdate.VehicleTypeId = updateVehicleVM.VehicleTypeId; vehicleToUpdate.BodyStyleId = updateVehicleVM.BodyStyleId; vehicleToUpdate.ModelYear = updateVehicleVM.ModelYear; vehicleToUpdate.TransmissionTypeId = updateVehicleVM.TransmissionTypeId; vehicleToUpdate.ColorId = updateVehicleVM.ColorId; vehicleToUpdate.InteriorColorId = updateVehicleVM.InteriorColorId; vehicleToUpdate.Mileage = updateVehicleVM.Mileage; vehicleToUpdate.MSRP = updateVehicleVM.MSRP; vehicleToUpdate.SalePrice = updateVehicleVM.SalePrice; vehicleToUpdate.Description = updateVehicleVM.Description; vehicleToUpdate.IsFeatured = updateVehicleVM.IsFeatured; repo.Update(vehicleToUpdate, modelToUpdate, makeToUpdate); return(RedirectToAction("Vehicles")); } var makesRepo = CarMakesRepositoryFactory.GetRepository(); var vehicleTypesRepo = VehicleTypesRepositoryFactory.GetRepository(); var bodyStylesRepo = BodyStylesRepositoryFactory.GetRepository(); var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository(); var colorsRepo = ColorsRepositoryFactory.GetRepository(); var interiorColorsRepo = InteriorColorsRepositoryFactory.GetRepository(); var vehiclesRepo = VehiclesRepositoryFactory.GetRepository(); var modelsRepo = CarModelsRepositoryFactory.GetRepository(); updateVehicleVM.SetMakeItems(makesRepo.GetAll()); updateVehicleVM.SetVehicleTypeItems(vehicleTypesRepo.GetAll()); updateVehicleVM.SetBodyStyleItems(bodyStylesRepo.GetAll()); updateVehicleVM.SetTransmissionTypeItems(transmissionTypesRepo.GetAll()); updateVehicleVM.SetColorItems(colorsRepo.GetAll()); updateVehicleVM.SetInteriorColorItems(interiorColorsRepo.GetAll()); updateVehicleVM.SetMakeModelItems(modelsRepo.GetDetailsAll()); return(View("UpdateVehicle", updateVehicleVM)); }
public ActionResult AddVehicle(AddVehicleVM addVehicleVM) { var duplicateVehicle = from v in VehiclesRepositoryFactory.GetRepository().GetAll() where v.VIN == addVehicleVM.VIN select v; if (duplicateVehicle.Count() != 0) { ModelState.AddModelError("VIN", "VIN already exists in database. Duplicate vehicles are not allowed."); } if (ModelState.IsValid) { var vehicleToAdd = new Vehicle(); var modelToAdd = new CarModel(); var makeToAdd = new CarMake(); var employeeId = int.Parse(User.Identity.GetEmployeeId()); vehicleToAdd.EmployeeId = employeeId; var repo = VehiclesRepositoryFactory.GetRepository(); if (addVehicleVM.File != null && addVehicleVM.File.ContentLength > 0) { var newId = repo.GetAll().Max(v => v.VehicleId) + 1; var fileSplit = Path.GetFileName(addVehicleVM.File.FileName).Split('.'); var fileExtension = fileSplit[fileSplit.Length - 1]; var fileName = "inventory-x-" + newId + "." + fileExtension; var path = Path.Combine(Server.MapPath("~/Images/"), fileName); addVehicleVM.File.SaveAs(path); vehicleToAdd.ImageFileName = fileName; } modelToAdd.Name = addVehicleVM.ModelName; makeToAdd.Name = addVehicleVM.MakeName; vehicleToAdd.VIN = addVehicleVM.VIN; vehicleToAdd.BodyStyleId = addVehicleVM.BodyStyleId; vehicleToAdd.ModelYear = addVehicleVM.ModelYear; vehicleToAdd.TransmissionTypeId = addVehicleVM.TransmissionTypeId; vehicleToAdd.ColorId = addVehicleVM.ColorId; vehicleToAdd.InteriorColorId = addVehicleVM.InteriorColorId; vehicleToAdd.Mileage = addVehicleVM.Mileage; vehicleToAdd.MSRP = addVehicleVM.MSRP; vehicleToAdd.SalePrice = addVehicleVM.SalePrice; vehicleToAdd.Description = addVehicleVM.Description; vehicleToAdd.VehicleTypeId = addVehicleVM.VehicleTypeId; repo.Insert(vehicleToAdd, modelToAdd, makeToAdd); return(RedirectToAction("Vehicles")); } var makesRepo = CarMakesRepositoryFactory.GetRepository(); var vehicleTypesRepo = VehicleTypesRepositoryFactory.GetRepository(); var bodyStylesRepo = BodyStylesRepositoryFactory.GetRepository(); var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository(); var colorsRepo = ColorsRepositoryFactory.GetRepository(); var interiorColorsRepo = InteriorColorsRepositoryFactory.GetRepository(); var modelsRepo = CarModelsRepositoryFactory.GetRepository(); addVehicleVM.SetMakeItems(makesRepo.GetAll()); addVehicleVM.SetVehicleTypeItems(vehicleTypesRepo.GetAll()); addVehicleVM.SetBodyStyleItems(bodyStylesRepo.GetAll()); addVehicleVM.SetTransmissionTypeItems(transmissionTypesRepo.GetAll()); addVehicleVM.SetColorItems(colorsRepo.GetAll()); addVehicleVM.SetInteriorColorItems(interiorColorsRepo.GetAll()); addVehicleVM.SetMakeModelItems(modelsRepo.GetDetailsAll()); return(View("AddVehicle", addVehicleVM)); }
public ModelsVM() { Models = CarModelsRepositoryFactory.GetRepository().GetDetailsAll(); ModelItemsInStock = CarModelsRepositoryFactory.GetRepository().GetDetailsAllInStock(); MakeItems = new List <SelectListItem>(); }