public ActionResult EditNews(News EditedNews, IFormFile UploadImg, string deletingImgPath) { if (ModelState.IsValid) { if (UploadImg != null && UploadImg.Length > 0) { // deleting old image from its path : if (System.IO.File.Exists(deletingImgPath)) { System.IO.File.Delete(deletingImgPath); } string ImgPath = Path.Combine(env.WebRootPath + "\\imageUploads\\NewsImg", UploadImg.FileName); UploadImg.CopyTo(new FileStream(ImgPath, FileMode.Create)); EditedNews.Image = UploadImg.FileName; bool successfullyEditingNews = DAL.EditExistedNews(EditedNews.ID, EditedNews); if (successfullyEditingNews) { return(RedirectToAction("GetAllNews")); } else { return(View(EditedNews)); } } else { ViewBag.Message = "You have not specified a file yet ..."; } } return(View(EditedNews)); }
public ActionResult EditNews(News EditedNews, HttpPostedFileBase UploadImg, string deletingImgPath) { if (ModelState.IsValid) { if (UploadImg != null && UploadImg.ContentLength > 0) { // deleting old image from its path : if (System.IO.File.Exists(deletingImgPath)) { System.IO.File.Delete(deletingImgPath); } string ImgPath = Path.Combine(Server.MapPath("~/imageUploads/NewsImg"), UploadImg.FileName); UploadImg.SaveAs(ImgPath); EditedNews.Image = UploadImg.FileName; bool successfullyEditingNews = DAL.EditExistedNews(EditedNews.ID, EditedNews); if (successfullyEditingNews) { return(RedirectToAction("GetAllNews")); } else { return(View(EditedNews)); } } else { ViewBag.Message = "You have not specified a file yet ..."; } } return(View(EditedNews)); }