public async Task <IActionResult> Edit(int id, AddBarViewModel vm) { try { var fileName = Path.Combine(hostingEnvironment.WebRootPath, Path.GetFileName(vm.Image.FileName)); vm.Image.CopyTo(new FileStream(fileName, FileMode.Create)); var imgPath = "/barImages/" + Path.GetFileName(vm.Image.FileName); var barToEdit = vm.MapToDTO(); barToEdit.ImagePath = imgPath; barToEdit.Id = id; await barServices.EditAsync(barToEdit); return(RedirectToAction("Details", new { id = id })); } catch (InvalidOperationException) { return(BadRequest()); } }