Exemplo n.º 1
0
        public async Task editPostAsync(string post_id, string content, List <string> delete, List <Post> news)
        {
            var post_collection    = dataContext.getConnection().GetCollection <Post>("Post");
            var post_comment       = dataContext.getConnection().GetCollection <Post_Comment>("Post_Comment");
            PostLikeManagement plm = new PostLikeManagement();
            var filter             = Builders <Post> .Filter.Eq("_id", ObjectId.Parse(post_id));

            var update = Builders <Post> .Update.Set(p => p.description, content);

            if (news != null)
            {
                foreach (Post p in news)
                {
                    await addSubPost(post_id, p);

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

                    await post_comment.InsertOneAsync(new Post_Comment { post_id = ObjectId.Parse(p._id), comments = new List <Comment>() });
                }
            }
            if (delete != null)
            {
                foreach (string _id in delete)
                {
                    await removeSubPost(post_id, _id);
                }
            }
            await post_collection.UpdateOneAsync(filter, update);
        }
Exemplo n.º 2
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>() });
                }
            }
        }
Exemplo n.º 3
0
        public async Task removeSubPost(string post_id, string sub_post_id)
        {
            PostLikeManagement plm = new PostLikeManagement();
            CommentManagement  cm  = new CommentManagement();
            var post_collection    = dataContext.getConnection().GetCollection <Post>("Post");
            var filter             = Builders <Post> .Filter.Eq("_id", ObjectId.Parse(post_id));

            var update = Builders <Post> .Update.PullFilter("video_image", Builders <Post> .Filter.Eq("_id", ObjectId.Parse(sub_post_id)));

            await post_collection.UpdateOneAsync(filter, update);

            await plm.remove_post_like(sub_post_id);

            await cm.remove_post_comment(sub_post_id);
        }