public PostsComments AddPostComment(PostsComments newPostComment) { if (newPostComment.post_id != null && newPostComment.post_id != 0 && newPostComment.text.Trim() != "") { PostsCommentsContext _db = new PostsCommentsContext(); _db.posts_comments.Add(newPostComment); _db.SaveChanges(); var postCommentId = _db.posts_comments.Select(id => id.id).Max(); newPostComment.id = postCommentId; return newPostComment; } return null; }
public ActionResult AddComment() { if (Session == null || Session["isAuth"] == null || (bool)Session["isAuth"] == false) return RedirectToAction("Login", "Account"); IPostsContext postsContext = new PostsContext(); IPostsCommentsContext postsCommentsContext = new PostsCommentsContext(); IUsersContext usersContext = new UsersContext(); PostsComments comment = new PostsComments(); int postId = Convert.ToInt32(Request.Form["postId"]); if (postId == 0) return RedirectToAction("Index", "Home"); comment.post_id = postId; comment.user_id = Convert.ToInt32(Request.Form["userId"]); comment.text = Request.Form["commentText"]; string url = Request.Form["postURL"]; if (Request.Form["commentText"] == null) if (url != null) return Redirect(url); else return RedirectToAction("Index", "Home"); comment = postsCommentsContext.AddPostComment(comment); return Redirect(url); }
public ActionResult DellComment() { if (Session == null || Session["isAuth"] == null || (bool)Session["isAuth"] == false) return RedirectToAction("Login", "Account"); IPostsContext postsContext = new PostsContext(); IPostsCommentsContext postsCommentsContext = new PostsCommentsContext(); IUsersContext usersContext = new UsersContext(); PostsComments comment = new PostsComments(); comment = postsCommentsContext.GetPostCommentById(Convert.ToInt32(Request.Form["commentId"])); if (comment == null) return RedirectToAction("Index", "Home"); postsCommentsContext.DellComment(comment.id); string url = "~/Post/PostPage?post=" + comment.post_id; return RedirectToAction("Index", "Home"); }