public ActionResult Edit(int id) { var v = repo.GetVehicleById(id); var model = new EditVehicleViewModel { VehicleId = v.VehicleId, VehicleMakeId = v.Model.VehicleMakeId, GetModel = v.Model, IsNew = v.VehicleIsNew, Year = v.Year, VIN = v.Vin, BodyStyle = v.BodyStyle, TransmissionType = v.TransmissionType, Color = v.Color, InteriorColor = v.InteriorColor, Odometer = v.Odometer, SalePrice = v.SalePrice, MSRP = v.MSRP, Description = v.Description, ImagePath = v.Image, Featured = v.VehicleFeatured, }; model.SetMakes(repo.GetAllMakes()); model.SetModels(repo.GetAllModels()); return(View(model)); }
public ActionResult Edit(EditVehicleViewModel model) { if (model.Image != null && model.Image.ContentLength > 0) { string picture = Path.GetFileName(model.Image.FileName); string imgPath = Path.Combine(Server.MapPath("~/Images/"), picture); model.Image.SaveAs(imgPath); model.ImagePath = "http://localhost:53012/Images/" + model.Image.FileName; } if (model.SalePrice > model.MSRP) { ModelState.AddModelError("SalePrice", "Sale price cannot exceed MSRP"); } if (ModelState.IsValid) { Vehicle editedVehicle = new Vehicle { VehicleId = model.VehicleId, Vin = model.VIN, Year = model.Year, BodyStyle = model.BodyStyle, Model = model.GetModel, Image = model.ImagePath, Color = model.Color, InteriorColor = model.InteriorColor, Odometer = model.Odometer, MSRP = model.MSRP, SalePrice = model.SalePrice, TransmissionType = model.TransmissionType, Description = model.Description, VehicleFeatured = model.Featured, VehicleIsNew = model.IsNew, }; repo.EditVehicle(editedVehicle); return(RedirectToAction("Admin")); } else { model.SetMakes(repo.GetAllMakes()); model.SetModels(repo.GetAllModels()); return(View(model)); } }