public ActionResult AddVehicle(VehicleViewModel model) { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { model.Vehicle.Image = model.ImageUpload.FileName.ToString(); } if (ModelState.IsValid) { model.Vehicle.UserName = User.Identity.GetUserName(); var vehicleRepo = VehicleRepositoryFactory.GetRepository(); vehicleRepo.Add(model.Vehicle); return(View("Vehicles")); } else { var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var bodyRepo = BodyStyleRepositoryFactory.GetRepository(); var transRepo = TransmissionRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); model.Makes = makeRepo.GetLookup(); model.Models = modelRepo.GetLookup(); model.DropDowns = VehicleTypeLookupmodel.NewUsedDropDownList(); model.BodyStyles = bodyRepo.GetAll(); model.Trans = transRepo.GetAll(); model.Colors = colorRepo.GetAll(); return(View(model)); } }
public ActionResult EditVehicle(int id) { var vehicleRepo = VehicleRepositoryFactory.GetRepository(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var bodyRepo = BodyStyleRepositoryFactory.GetRepository(); var transRepo = TransmissionRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); VehicleViewModel model = new VehicleViewModel(); model.Vehicle = vehicleRepo.GetByID(id); model.Makes = makeRepo.GetLookup(); model.Models = modelRepo.GetLookupByMake(model.Vehicle.MakeID); model.DropDowns = VehicleTypeLookupmodel.NewUsedDropDownList(); model.BodyStyles = bodyRepo.GetAll(); model.Trans = transRepo.GetAll(); model.Colors = colorRepo.GetAll(); if (ModelState.IsValid) { return(View(model)); } else { return(View("Vehicles")); } }
public ActionResult AddVehicle() { VehicleViewModel model = new VehicleViewModel(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var bodyRepo = BodyStyleRepositoryFactory.GetRepository(); var transRepo = TransmissionRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); model.Makes = makeRepo.GetLookup(); model.Models = modelRepo.GetLookup(); model.DropDowns = VehicleTypeLookupmodel.NewUsedDropDownList(); model.BodyStyles = bodyRepo.GetAll(); model.Trans = transRepo.GetAll(); model.Colors = colorRepo.GetAll(); return(View(model)); }