public IActionResult EditBranch(EditBranchViewModel model) { var branch = _branch.GetById(model.Id); if (ModelState.IsValid) { branch.Id = model.Id; branch.Name = model.Name; branch.Address = model.Address; branch.Telephone = model.Telephone; branch.Description = model.Description; branch.OpenDate = model.OpenDate; if (model.ImageUrl != null) { //if (model.ExistingImageName != null) //{ // var filepath = _hostingEnvironment.WebRootPath; // string name = model.ExistingImageName; // string filepaths = Path.Combine(filepath, name); // System.IO.File.Delete(filepaths); //} branch.ImageUrl = UploadFileMethod(model); _branch.Update(branch); return(RedirectToAction("Detail", new { id = model.Id })); } branch.ImageUrl = model.ExistingImageName; //call the update method _branch.Update(branch); return(RedirectToAction("Detail", new { id = model.Id })); } return(View()); }