public ActionResult PhotosAddOrEdit(int id = 0) { if (id == 0) { owl_PhotoGallery photoGallety = new owl_PhotoGallery(); return(View(photoGallety)); } else { MasterContext dbContext = new MasterContext(); var photoGalletyModel = dbContext.PhotoGallery.First(q => q.Id == id); return(View(photoGalletyModel)); } }
public ActionResult PhotosAddOrEdit(owl_PhotoGallery model) { try { if (model.ImageFile.ContentLength > 0) { string _filename = Path.GetFileName(model.ImageFile.FileName); string _path = Path.Combine(Server.MapPath("/assets/Uploads/"), _filename); model.ImageFile.SaveAs(_path); model.Image = _filename; } if (model.Id == 0) { MasterContext photoGalleryadd = new MasterContext(); owl_PhotoGallery photoGallety = new owl_PhotoGallery() { Name = model.Name, Info = model.Info, Image = model.Image, }; photoGalleryadd.PhotoGallery.Add(photoGallety); photoGalleryadd.SaveChanges(); ViewBag.message = "Resim Eklendi Eklendi"; ModelState.Clear(); return(Redirect("/Media/PhotosList")); } else { MasterContext photoGalleryadd = new MasterContext(); photoGalleryadd.Entry(model).State = System.Data.Entity.EntityState.Modified; photoGalleryadd.SaveChanges(); return(Redirect("/Media/PhotosList")); } } catch (Exception) { throw; } }