public static Comment AddComment(Comment comment) { PostCommentContext context = new PostCommentContext(); context.Comments.Add(comment); context.SaveChanges(); return(comment); }
public static Post AddPost(Post post) { PostCommentContext context = new PostCommentContext(); context.Posts.Add(post); context.SaveChanges(); return(post); }
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(); }
public static Comment GetCommentById(Guid id) { PostCommentContext context = new PostCommentContext(); return(context.Comments.Where(c => c.CommentId == id).FirstOrDefault()); }
public static List <Post> GetAllPosts() { PostCommentContext context = new PostCommentContext(); return(context.Posts.Include(p => p.Comments).ToList()); }
public static Post GetPostById(Guid id) { PostCommentContext context = new PostCommentContext(); return(context.Posts.Where(p => p.PostId == id).FirstOrDefault()); }