示例#1
0
        public static Comment AddComment(Comment comment)
        {
            PostCommentContext context = new PostCommentContext();

            context.Comments.Add(comment);
            context.SaveChanges();
            return(comment);
        }
示例#2
0
        public static Post AddPost(Post post)
        {
            PostCommentContext context = new PostCommentContext();

            context.Posts.Add(post);
            context.SaveChanges();
            return(post);
        }
示例#3
0
        public static void DeletePost(Guid id)
        {
            PostCommentContext context = new PostCommentContext();
            Post post = GetPostById(id);

            if (post == null)
            {
                throw new NotFoundException();
            }
            context.Posts.Remove(post);
            context.SaveChanges();
        }
示例#4
0
        public static Comment GetCommentById(Guid id)
        {
            PostCommentContext context = new PostCommentContext();

            return(context.Comments.Where(c => c.CommentId == id).FirstOrDefault());
        }
示例#5
0
        public static List <Post> GetAllPosts()
        {
            PostCommentContext context = new PostCommentContext();

            return(context.Posts.Include(p => p.Comments).ToList());
        }
示例#6
0
        public static Post GetPostById(Guid id)
        {
            PostCommentContext context = new PostCommentContext();

            return(context.Posts.Where(p => p.PostId == id).FirstOrDefault());
        }