public IActionResult Edit(ViewEditModel viewEditModel) { if (ModelState.IsValid) { Galleries galleries = mercyContext1.Galleries.Find(viewEditModel.Id); galleries.Id = viewEditModel.Id; galleries.Name = viewEditModel.Name; if (viewEditModel.Photo != null) { if (viewEditModel.CurrentPhoto != null) { string file = Path.Combine(iwebHostEnvironment.WebRootPath, "images", viewEditModel.CurrentPhoto); //if (file!=null) //{ System.IO.File.Delete(file); //} //else //{ // return View("Picture already Exist."); //} } galleries.Photo = NewMethod(viewEditModel); } mercyContext1.Update(galleries); mercyContext1.SaveChanges(); return(RedirectToAction("UploadInfo", "Account")); } return(View()); }
public IActionResult Gallery(Gallery gallery) { if (ModelState.IsValid) { string uniqueFileName = null; uniqueFileName = MethodExtraction(gallery, uniqueFileName); Galleries galleris = new Galleries { Id = gallery.Id, Name = gallery.Name, Photo = uniqueFileName, }; _mercyContext.Add(galleris); _mercyContext.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }