public ActionResult Index() { List <Post> allPosts = new List <Post> (Post.GetAll()); ControllersHelper.SetLoginData(Request, ViewBag); return(View(allPosts)); }
public ActionResult Delete(int id) { ControllersHelper.SetLoginData(Request, ViewBag); ERUser user = ViewBag.user; Post post = Post.GetByID(id); if (post != null && ViewBag.isLoggedIn && user.GetID() == post.GetUserID()) { post.Delete(); } return(Redirect("/")); }
public ActionResult Details(int id) { ControllersHelper.SetLoginData(Request, ViewBag); Post post = Post.GetByID(id); if (post != null) { Console.WriteLine(post.GetTitle()); Console.WriteLine(post.GetUserID()); return(View(post)); } else { return(Redirect("/")); } }
public ActionResult AddReply(int postid, int parentid) { ControllersHelper.SetLoginData(Request, ViewBag); ERUser user = ViewBag.user; Post post = Post.GetByID(postid); Comment parent = Comment.GetByID(parentid); if (post != null && parent != null && ViewBag.isLoggedIn) { string body = Request.Form["comment-body"]; Comment comment = new Comment(body, user.GetID(), post.GetID(), -1, parent.GetID()); comment.Save(); return(Redirect($"/posts/{postid}")); } return(Redirect($"/posts/{postid}")); }
public ActionResult Update(int id) { ControllersHelper.SetLoginData(Request, ViewBag); ERUser user = ViewBag.user; Post post = Post.GetByID(id); if (post != null && ViewBag.isLoggedIn && user.GetID() == post.GetUserID()) { string newBody = Request.Form["postsBody"]; post.Edit(newBody); return(Redirect($"/posts/{post.GetID()}")); } else { return(Redirect("/")); } }
public ActionResult Create() { ControllersHelper.SetLoginData(Request, ViewBag); string title = Request.Form["postsTitle"]; string body = Request.Form["postsBody"]; if (ViewBag.isLoggedIn) { Post newPost = new Post(title, body, ViewBag.user.GetID()); newPost.Save(); return(Redirect($"/posts/{newPost.GetID()}")); } else { return(Redirect("/")); } }
public ActionResult New() { ControllersHelper.SetLoginData(Request, ViewBag); return(View()); }