public ActionResult View_Post(int id) { Rep_posts post = new Rep_posts(); Tbl_Posts posts = post.Get_Post(id); if (Session["User"] != null) { NewsDB db = new NewsDB(); string s = Session["User"].ToString(); ViewBag.user = s; int ids = db.Tbl_User.Where(x => x.User_Name.Equals(s)).SingleOrDefault().User_id;; ViewBag.id = ids; } return(View(posts)); }
public ActionResult Add_Post(Tbl_Posts p, string Isbreak, HttpPostedFileBase file) { Tbl_Posts post = new Tbl_Posts(); string s = Session["User"].ToString(); int id = db.Tbl_User.Where(x => x.User_Name.Equals(s)).SingleOrDefault().User_id;; post.Post_Description = p.Post_Description; if (Isbreak == null) { post.Post_IsBreaking = false; } else { post.Post_IsBreaking = true; } post.Post_Summery = p.Post_Summery; post.Post_Title = p.Post_Title; post.Post_Userid = id; if (file != null) { string path = "~/Content/News/Photo/"; var filename = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath(Path.Combine(path, filename))); post.Post_Image = "../Content/News/Photo/" + filename; } else { post.Post_Image = "../Content/News/Photo/no_image.jpg"; } //post.Post_Image = p.Post_Image; post.Post_Date = DateTime.Now; post.Post_Catid = 1; db.Tbl_Posts.Add(post); if (Convert.ToBoolean(db.SaveChanges() > 0)) { ViewBag.id = id; ViewBag.user = s; return(RedirectToAction("User_Profile")); } else { TempData["message"] = "عملیات با شکست مواجه شد"; TempData["info"] = "error"; return(RedirectToAction("Message", "Register")); } }
public Tbl_Posts Get_Post(int id) { Tbl_Posts q = db.Tbl_Posts.Where(x => x.Post_id == id).SingleOrDefault(); return(q); }