public ActionResult AddCar(Car car, IEnumerable <HttpPostedFileBase> fileUpload) { if (car.EngineVolume < 0) { ModelState.AddModelError("EngineVolume", "Engine volume must be greather then 0"); } if (car.EnginePower < 0) { ModelState.AddModelError("EnginePower", "Engine power must be greather then 0"); } if (car.Price < 0) { ModelState.AddModelError("Price", "Price must be greather then 0"); } if (ModelState.IsValid) { if (CRUDCars.AddCar(car, fileUpload)) { ViewBag.NewCar = car.Make + " " + car.Model; return(View("Index")); } else { return(View("Error")); } } else { return(View("AddCar")); } }
public ActionResult Show(int id) { if (CRUDCars.GetCarById(id) != null) { ViewData.Model = CRUDCars.GetCarById(id); return(View("Show")); } else { return(View("Error")); } }
public ActionResult RemoveCar(int id) { List <Image> images = CRUDCars.RemoveCar(id); if (images != null) { foreach (Image item in images) { string path = Path.Combine(Server.MapPath("~/images"), item.ProductImage); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } return(View("Index")); } else { return(View("Error")); } }