public async Task <Comment> insertComment(string post_id, Comment comment) { PostParticipantManagement ppm = new PostParticipantManagement(); var post_comments_collection = dataContext.getConnection().GetCollection <BsonDocument>("Post_Comment"); var filter = Builders <BsonDocument> .Filter.Eq("_id", ObjectId.Parse(post_id)); comment._id = ObjectId.GenerateNewId().ToString(); comment.sub_comments = new List <Comment>(); comment.date_created = DateTime.Now; var update = Builders <BsonDocument> .Update.AddToSet("comments", comment); await post_comments_collection.UpdateOneAsync(filter, update); await lm.insertCommentLike(new Comment_Like { comment_id = comment._id, like_Records = new List <Like_Record>() }); if (!ppm.has_participated(post_id, comment.owner._id)) { await ppm.insertPostParticipantRecord(post_id, new Participant { _id = comment.owner._id, email = comment.owner.email, status = true }); } //await ppm.send_email_to_participantsAsync(post_id, comment.owner._id,comment.owner.user_name, // comment.owner.user_name + " has commented on "); return(comment); }
public async Task <Comment> insert_subCommentAsync(string post_id, string comment_id, Comment comment) { PostParticipantManagement ppm = new PostParticipantManagement(); comment._id = ObjectId.GenerateNewId().ToString(); comment.sub_comments = null; var post_comments_collection = dataContext.getConnection().GetCollection <Post_Comment>("Post_Comment"); var filter = Builders <Post_Comment> .Filter.And( Builders <Post_Comment> .Filter.Where(x => x.post_id == ObjectId.Parse(post_id)), Builders <Post_Comment> .Filter.Eq("comments._id", comment_id)); var update = Builders <Post_Comment> .Update.Push("comments.$.sub_comments", comment); await post_comments_collection.FindOneAndUpdateAsync(filter, update); await lm.insertCommentLike(new Comment_Like { comment_id = comment._id, like_Records = new List <Like_Record>() }); if (!ppm.has_participated(post_id, comment.owner._id)) { await ppm.insertPostParticipantRecord(post_id, new Participant { _id = comment.owner._id, email = comment.owner.email, status = true }); } return(comment); }