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(); } }
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(); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public ForumDBContext GetContext() { ForumDBContext sdc = new ForumDBContext(ConfigurationManager.ConnectionStrings["ForumDBContext"].ToString()); return(sdc); }