public ActionResult Create(tbl_post post, string context, string Title, HttpPostedFileBase image) { if (ModelState.IsValid) { //tbl_post post = new tbl_post(); tbl_photo photo = new tbl_photo(); post.Title = Title; post.Context = context; if (image != null) { string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; db.SaveChanges(); } var imagecopy = db.tbl_photo.Add(photo); post.PhotoId = imagecopy.PhotoId; post.Accept = false; post.Active = true; post.Views = 0; post.AuthorId = db.aspnet_Users.FirstOrDefault(x => x.UserName == User.Identity.Name).UserId; post.DateTime = DateTime.Now; db.tbl_post.Add(post); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult EvvelkiPost(int id) { tbl_post pst = db.tbl_post.FirstOrDefault(x => x.PostId == id); pst.PostId--; return(View()); }
public ActionResult Edit(int id, tbl_post post, HttpPostedFileBase Sekil) { if (ModelState.IsValid) { var p = db.tbl_post.Where(x => x.PostId == id).SingleOrDefault(); if (Sekil != null) { if (System.IO.File.Exists(Server.MapPath(p.tbl_sekil.Boyuk))) { System.IO.File.Delete(Server.MapPath(p.tbl_sekil.Boyuk)); } WebImage img = new WebImage(Sekil.InputStream); FileInfo fileinfo = new FileInfo(Sekil.FileName); string imagename = Guid.NewGuid().ToString() + fileinfo.Extension; img.Save("~/Upload/Sekiller/boyuk" + imagename); p.tbl_sekil.Boyuk = "/Upload/Sekiller/boyuk" + imagename; } p.Baslig = post.Baslig; p.CategoryId = post.CategoryId; p.Context = post.Context; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult PostDetail(int id) { ViewBag.Istifadeci = Session["Istifadeci"]; tbl_post post = db.tbl_post.FirstOrDefault(x => x.PostId == id); return(View(post)); }
public void Baxildi(int id) { tbl_post pst = db.tbl_post.FirstOrDefault(x => x.PostId == id); pst.Baxis++; db.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { tbl_post tbl_post = db.tbl_post.Find(id); db.tbl_post.Remove(tbl_post); db.SaveChanges(); return(RedirectToAction("Index")); }
public string PostBeyen(int id) { tbl_post pst = db.tbl_post.FirstOrDefault(x => x.PostId == id); pst.Beyenme++; db.SaveChanges(); return(pst.Beyenme.ToString()); }
public ActionResult MeqaleTesdiqle(tbl_post post, int id) { tbl_post pst = db.tbl_post.FirstOrDefault(x => x.PostId == id); pst.QebulEdildi = true; TempData["InfoM"] = "Məqalə uğurlu şəkildə əlavə oldu"; db.SaveChanges(); return(RedirectToAction("MeqaleAktivlesdir")); }
public ActionResult Delete(int id) { tbl_post post = db.tbl_post.Find(id); if (System.IO.File.Exists(Server.MapPath(post.tbl_photo.URL))) { System.IO.File.Delete(Server.MapPath(post.tbl_photo.URL)); } db.tbl_post.Remove(post); db.SaveChanges(); TempData["Xeber"] = "Məqalə uğurla silindi"; return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "PostId,MuellifId,Baslig,Context,PhotoId,CategoryId,Tarixi,Baxis,Beyenme,Keyword")] tbl_post tbl_post) { if (ModelState.IsValid) { db.Entry(tbl_post).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.tbl_category, "CategoryId", "Ad", tbl_post.CategoryId); ViewBag.PhotoId = new SelectList(db.tbl_sekil, "PhotoId", "Kicik", tbl_post.PhotoId); ViewBag.MuellifId = new SelectList(db.tbl_users, "UserId", "Ad", tbl_post.MuellifId); return(View(tbl_post)); }
// GET: AdminPanel/tbl_post/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_post tbl_post = db.tbl_post.Find(id); if (tbl_post == null) { return(HttpNotFound()); } return(View(tbl_post)); }
public ActionResult Edit([Bind(Include = "PostId,Baslig,Context,Tarixi,PostTypeId,CategoryId,MuellifId,SekilId,Baxis,Beyen,Aktiv")] tbl_post tbl_post) { if (ModelState.IsValid) { db.Entry(tbl_post).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.tbl_category, "CategoryId", "Ad", tbl_post.CategoryId); ViewBag.MuellifId = new SelectList(db.tbl_users, "MuellifId", "Adi", tbl_post.MuellifId); ViewBag.PostTypeId = new SelectList(db.tbl_post_type, "PostTypeId", "Adi", tbl_post.PostTypeId); ViewBag.SekilId = new SelectList(db.tbl_sekil, "SekilId", "Balacasekil", tbl_post.SekilId); return(View(tbl_post)); }
// GET: AdminPanel/tbl_post1/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_post tbl_post = db.tbl_post.Find(id); if (tbl_post == null) { return(HttpNotFound()); } ViewBag.CategoryId = new SelectList(db.tbl_category, "CategoryId", "Ad", tbl_post.CategoryId); ViewBag.PhotoId = new SelectList(db.tbl_sekil, "PhotoId", "Kicik", tbl_post.PhotoId); ViewBag.MuellifId = new SelectList(db.tbl_users, "UserId", "Ad", tbl_post.MuellifId); return(View(tbl_post)); }
public ActionResult MeqaleYaz([Bind(Include = "PostId,MuellifId,Baslig,Context,PhotoId,CategoryId,Tarixi,Baxis,Beyenme,Keyword")] tbl_post post, HttpPostedFileBase sekil, string etiket) { tbl_etiket etkt = new tbl_etiket(); ViewBag.CategoryId = new SelectList(db.tbl_category, "CategoryId", "Ad"); string[] etikets = etiket.Split(','); foreach (var e in etikets) { tbl_etiket etk = db.tbl_etiket.FirstOrDefault(x => x.Ad.ToLower() == e.ToLower().Trim()); if (etk == null) { etk = new tbl_etiket(); etk.Ad = e; db.tbl_etiket.Add(etk); db.SaveChanges(); } post.tbl_etiket.Add(etk); db.SaveChanges(); } Image img = Image.FromStream(sekil.InputStream); Bitmap boyuksekil = new Bitmap(img, Settings.SekilBoyukBoy); Bitmap kiciksekil = new Bitmap(img, Settings.SekilKicikBoy); Bitmap ortasekil = new Bitmap(img, Settings.SekilOrtaBoy); boyuksekil.Save(Server.MapPath("/Upload/Sekiller/boyuk" + sekil.FileName)); kiciksekil.Save(Server.MapPath("/Upload/Sekiller/balaca" + sekil.FileName)); ortasekil.Save(Server.MapPath("/Upload/Sekiller/orta" + sekil.FileName)); tbl_sekil skl = new tbl_sekil(); skl.Boyuk = "/Upload/Sekiller/boyuk" + sekil.FileName; db.tbl_sekil.Add(skl); db.SaveChanges(); post.PhotoId = skl.PhotoId; post.QebulEdildi = false; post.Tarixi = DateTime.Now; post.Baxis = 0; post.Beyenme = 0; int yzrId = db.tbl_users.FirstOrDefault(x => x.Login == User.Identity.Name).UserId; post.MuellifId = yzrId; db.tbl_post.Add(post); db.SaveChanges(); return(View()); }
// GET: AdminPanel/tbl_post/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_post tbl_post = db.tbl_post.Find(id); if (tbl_post == null) { return(HttpNotFound()); } ViewBag.CategoryId = new SelectList(db.tbl_category, "CategoryId", "Ad", tbl_post.CategoryId); ViewBag.MuellifId = new SelectList(db.tbl_users, "MuellifId", "Adi", tbl_post.MuellifId); ViewBag.PostTypeId = new SelectList(db.tbl_post_type, "PostTypeId", "Adi", tbl_post.PostTypeId); ViewBag.SekilId = new SelectList(db.tbl_sekil, "SekilId", "Balacasekil", tbl_post.SekilId); return(View(tbl_post)); }
public ActionResult Create([Bind(Include = "PostId,Baslig,Context,Tarixi,PostTypeId,CategoryId,MuellifId,SekilId,Baxis,Beyen,Aktiv")] tbl_post tbl_post, HttpPostedFileBase Sekil, string etiketler) { if (ModelState.IsValid) { if (tbl_post != null) { tbl_users aktiv = Session["Istifadeci"] as tbl_users; tbl_post.Tarixi = DateTime.Now; tbl_post.PostTypeId = 1; tbl_post.MuellifId = aktiv.MuellifId; tbl_post.SekilId = SekilYukle(Sekil); db.tbl_post.Add(tbl_post); db.SaveChanges(); string[] etikets = etiketler.Split(','); foreach (string etiket in etikets) { tbl_etiket etk = db.tbl_etiket.FirstOrDefault(x => x.Ad.ToLower() == etiket.ToLower().Trim()); if (etk != null) { etk = new tbl_etiket(); etk.Ad = etiket; db.tbl_etiket.Add(etk); db.SaveChanges(); } tbl_post.tbl_etiket.Add(etk); db.SaveChanges(); } } db.tbl_post.Add(tbl_post); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.tbl_category, "CategoryId", "Ad", tbl_post.CategoryId); ViewBag.MuellifId = new SelectList(db.tbl_users, "MuellifId", "Adi", tbl_post.MuellifId); ViewBag.PostTypeId = new SelectList(db.tbl_post_type, "PostTypeId", "Adi", tbl_post.PostTypeId); ViewBag.SekilId = new SelectList(db.tbl_sekil, "SekilId", "Balacasekil", tbl_post.SekilId); return(View(tbl_post)); }
public ActionResult Edit(int?id, string Title, string Context, HttpPostedFileBase image, tbl_post post) { if (ModelState.IsValid) { tbl_photo photo = new tbl_photo(); var selectedPost = db.tbl_post.Where(x => x.PostId == id).SingleOrDefault(); if (image != null) { if (System.IO.File.Exists(Server.MapPath(selectedPost.tbl_photo.URL))) { System.IO.File.Delete(Server.MapPath(selectedPost.tbl_photo.URL)); } string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; var imagecopy = db.tbl_photo.Add(photo); selectedPost.PhotoId = imagecopy.PhotoId; db.SaveChanges(); } selectedPost.Title = Title; selectedPost.Context = Context; db.SaveChanges(); } return(RedirectToAction("Index")); }