public ActionResult AddCar(CarAddEdditVM model) { CarRepoADO repoc = new CarRepoADO(); CarComponentRepoADO repo = new CarComponentRepoADO(); if (model.UploadedFile != null && model.UploadedFile.ContentLength > 0) { if (model.UploadedFile.ContentType == "image/jpeg" || model.UploadedFile.ContentType == "image/png") { string path = Path.Combine(Server.MapPath("~/Uploads"), Path.GetFileName(model.UploadedFile.FileName)); model.UploadedFile.SaveAs(path); model.AddCar.ImageFileName = model.UploadedFile.FileName; } else { ModelState.AddModelError("UploadedFile", "The uploaded file must be of type .jpg or .png"); } } if (ModelState.IsValid) { repoc.AddCar(model.AddCar); return(RedirectToAction("index", "home")); } else { model.SetSelectList(repo.GetModels(), repo.GetMakes(), repo.GetColors(), repo.GetInteriors(), repo.GetBodies(), repo.GetTrans()); return(View("AddCar", model)); } }
//[HttpGet] public ActionResult AddCar() { CarAddEdditVM model = new CarAddEdditVM(); CarComponentRepoADO repo = new CarComponentRepoADO(); model.SetSelectList(repo.GetModels(), repo.GetMakes(), repo.GetColors(), repo.GetInteriors(), repo.GetBodies(), repo.GetTrans()); return(View(model)); }
public ActionResult EditCar(int CarID) { CarAddEdditVM model = new CarAddEdditVM(); CarComponentRepoADO repo = new CarComponentRepoADO(); CarRepoADO repoc = new CarRepoADO(); model.SetSelectList(repo.GetModels(), repo.GetMakes(), repo.GetColors(), repo.GetInteriors(), repo.GetBodies(), repo.GetTrans()); model.AddCar = repoc.GetCarByID(CarID); foreach (SelectListItem make in model.MakeChoices) { if (int.Parse(make.Value) == model.AddCar.MakeID) { make.Selected = true; } } foreach (SelectListItem m in model.ModelChoices) { if (int.Parse(m.Value) == model.AddCar.ModelID) { m.Selected = true; } } foreach (SelectListItem color in model.ColorChoices) { if (int.Parse(color.Value) == model.AddCar.Color) { color.Selected = true; } } foreach (SelectListItem i in model.InteriorChoices) { if (int.Parse(i.Value) == model.AddCar.Interior) { i.Selected = true; } } return(View(model)); }