예제 #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());
        }