Beispiel #1
0
        public async Task insertPostAsync(Post post)
        {
            var post_collection = dataContext.getConnection().GetCollection <Post>("Post");
            await post_collection.InsertOneAsync(post);

            var post_comment = dataContext.getConnection().GetCollection <Post_Comment>("Post_Comment");
            await post_comment.InsertOneAsync(new Post_Comment { post_id = ObjectId.Parse(post._id), comments = new List <Comment>() });

            PostLikeManagement        plm = new PostLikeManagement();
            PostParticipantManagement ppm = new PostParticipantManagement();
            await ppm.insertPostParticipantAsync(new PostParticipant { _id = post._id, participants = new List <Participant>() });

            await ppm.insertPostParticipantRecord(post._id, new Participant { _id = post.owner._id, email = post.owner.email, status = true });

            await plm.insertPostLike(new Post_Like { post_id = post._id, like_Records = new List <Like_Record>() });

            if (post.video_image != null)
            {
                foreach (Post v in post.video_image)
                {
                    await plm.insertPostLike(new Post_Like { post_id = v._id, like_Records = new List <Like_Record>() });

                    await post_comment.InsertOneAsync(new Post_Comment { post_id = ObjectId.Parse(v._id), comments = new List <Comment>() });
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }