コード例 #1
0
ファイル: PostsComments.cs プロジェクト: Alfa512/TestTask
 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;
 }
コード例 #2
0
ファイル: PostController.cs プロジェクト: Alfa512/TestTask
        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);
        }
コード例 #3
0
ファイル: PostController.cs プロジェクト: Alfa512/TestTask
        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");
        }