public async Task AddBlogModerator(int blogId, ApplicationUser user) { var blog = await GetBlogById(blogId); blog.BlogModerators.Add(new BlogModerator() { Blog = blog, Moderator = user }); _context.Update(blog); await _context.SaveChangesAsync(); }
public async Task AddPostComment(int postId, ApplicationUser author, Comment comment, int parentCommentId) { var post = await GetPostById(postId); comment.Author = author; comment.Post = post; comment.CreatedDate = DateTime.Now; comment.UpdatedDate = comment.UpdatedDate; if (parentCommentId != 0) { comment.ParentCommentId = (int)parentCommentId; var parentComment = await _context.Comment.Include(m => m.ChildComments).SingleOrDefaultAsync(m => m.CommentId == parentCommentId); if (parentComment != null) { parentComment.ChildComments.Add(comment); _context.Update(parentComment); } } _context.Comment.Add(comment); post.Comments.Add(comment); _context.Update(post); await _context.SaveChangesAsync(); }