public async Task <IActionResult> Edit(Yayin yayin, IFormFile image) { if (image != null) { if (System.IO.File.Exists(_env.WebRootPath + yayin.ImageUrl)) { System.IO.File.Delete(_env.WebRootPath + yayin.ImageUrl); } if (image == null || image.Length == 0) { return(Content("not image selected")); } var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/image/Yayincilar", image.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await image.CopyToAsync(stream); } yayin.ImageUrl = "/image/Yayincilar/" + image.FileName; } _yayinService.Update(yayin); return(RedirectToAction("Index")); }