コード例 #1
0
 public void DeletePost(PostThread post)
 {
     using (ForumDBContext dc = conn.GetContext())
     {
         dc.PostThreads.DeleteObject(dc.PostThreads.Where
                                         (ac => ac.PostID.Equals(post.PostID)).FirstOrDefault());
         dc.SaveChanges();
     }
 }
コード例 #2
0
 public void DeleteComment(Comment comment)
 {
     using (ForumDBContext dc = conn.GetContext())
     {
         dc.Comments.DeleteObject(dc.Comments.Where
                                      (ac => ac.CommentID.Equals(comment.CommentID)).FirstOrDefault());
         dc.SaveChanges();
     }
 }
コード例 #3
0
        public PostThread GetPostByID(int PostID)
        {
            PostThread post = null;

            using (ForumDBContext dc = conn.GetContext())
            {
                post = (from a in dc.PostThreads where a.PostID == PostID select a).FirstOrDefault();
            }
            return(post);
        }
コード例 #4
0
        public Comment GetCommentByID(int CommentID)
        {
            Comment comment = null;

            using (ForumDBContext dc = conn.GetContext())
            {
                comment = (from a in dc.Comments where a.CommentID == CommentID select a).FirstOrDefault();
            }
            return(comment);
        }
コード例 #5
0
        public List <PostThread> GetContainsPosts(List <int> postIDs)
        {
            IEnumerable <PostThread> posts = null;

            List <PostThread> result = new List <PostThread>();

            using (ForumDBContext dc = conn.GetContext())
            {
                posts = (from a in dc.PostThreads where postIDs.Contains(a.PostID) select a);

                result = posts.ToList();
            }
            return(result);
        }
コード例 #6
0
        public List <PostThread> GetAllPosts()
        {
            IEnumerable <PostThread> posts = null;

            List <PostThread> result = new List <PostThread>();

            using (ForumDBContext dc = conn.GetContext())
            {
                posts = (from a in dc.PostThreads select a);

                result = posts.ToList();
            }
            return(result);
        }
コード例 #7
0
        public List <Comment> GetCommentByPostID(int PostID)
        {
            IEnumerable <Comment> comments = null;

            List <Comment> result = new List <Comment>();


            using (ForumDBContext dc = conn.GetContext())
            {
                comments = (from a in dc.Comments where a.PostID == PostID select a);

                result = comments.ToList();
            }
            return(result);
        }
コード例 #8
0
        public PostThread SavePost(PostThread post)
        {
            using (ForumDBContext dc = conn.GetContext())
            {
                if (post.PostID > 0)
                {
                    dc.PostThreads.Attach(new PostThread {
                        PostID = post.PostID
                    });
                    dc.PostThreads.ApplyCurrentValues(post);
                }
                else
                {
                    dc.PostThreads.AddObject(post);
                }
                dc.SaveChanges();
            }

            return(post);
        }
コード例 #9
0
        public Comment SaveComment(Comment comment)
        {
            using (ForumDBContext dc = conn.GetContext())
            {
                if (comment.CommentID > 0)
                {
                    dc.Comments.Attach(new Comment {
                        CommentID = comment.CommentID
                    });
                    dc.Comments.ApplyCurrentValues(comment);
                }
                else
                {
                    dc.Comments.AddObject(comment);
                }
                dc.SaveChanges();
            }

            return(comment);
        }
コード例 #10
0
        public ForumDBContext GetContext()
        {
            ForumDBContext sdc = new ForumDBContext(ConfigurationManager.ConnectionStrings["ForumDBContext"].ToString());

            return(sdc);
        }