public ActionResult Edit(CarVM carVM, HttpPostedFileBase image) {//Delete the old Phot from the folder try { var fileName = Path.GetFileName(image.FileName); var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName); image.SaveAs(path); carVM.Image = fileName; carVM.DealerId = User.Identity.GetUserId(); if (ModelState.IsValid) { if (carAppService.UpdateCar(carVM)) { return(RedirectToAction("Index")); } else { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name", carVM.BrandId); return(View(carVM)); } } else { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name", carVM.BrandId); return(View(carVM)); } } catch (Exception) { ViewBag.BrandId = new SelectList(unitOfWork.Brand.GetAll(), "ID", "Name", carVM.BrandId); return(View(carVM)); } }