public async Task sub_post_like(string post_id, string sub_post_id, string emo, Owner user_Session)
        {
            Like_Record like_Record = new Like_Record
            {
                emoji        = emo,
                user_name    = user_Session.user_name,
                user_picture = user_Session.user_picture,
                _id          = user_Session._id
            };
            PostLikeManagement plm = new PostLikeManagement();

            if (plm.has_like(sub_post_id, like_Record))
            {
                if (plm.get_like(sub_post_id, user_Session._id) == emo)
                {
                    await plm.remove_post_like_record(sub_post_id, like_Record);

                    await plm.update_sub_post_like_count(post_id, sub_post_id, emo, -1);
                }
                else
                {
                    await plm.update_sub_post_like_count(post_id, sub_post_id, plm.get_like(sub_post_id, user_Session._id), -1);

                    await plm.update_sub_post_like_count(post_id, sub_post_id, emo, 1);

                    await plm.update_post_like_record(sub_post_id, like_Record);
                }
            }
            else
            {
                await plm.insertLikeRecord(sub_post_id, like_Record);

                await plm.update_sub_post_like_count(post_id, sub_post_id, emo, 1);
            }
        }
Exemplo n.º 2
0
        public async Task remove_like_record(string comment_id, Like_Record like_Record)
        {
            var comment_like_collection = dataContext.getConnection().GetCollection <Comment_Like>("Comment_Like");
            var filter = Builders <Comment_Like> .Filter.Where(x => x.comment_id == comment_id);

            var update = Builders <Comment_Like> .Update.PullFilter("like_records", Builders <Like_Record> .Filter.Eq("_id", ObjectId.Parse(like_Record._id)));

            await comment_like_collection.UpdateOneAsync(filter, update);
        }
Exemplo n.º 3
0
        public async Task insertLikeRecord(string comment_id, Like_Record like_Record)
        {
            var comment_like_collection = dataContext.getConnection().GetCollection <Comment_Like>("Comment_Like");
            var filter = Builders <Comment_Like> .Filter.Eq("_id", ObjectId.Parse(comment_id));

            var update = Builders <Comment_Like> .Update.AddToSet("like_records", like_Record);

            await comment_like_collection.UpdateOneAsync(filter, update);
        }
Exemplo n.º 4
0
        public async Task insertLikeRecord(string post_id, Like_Record like_Record)
        {
            dataContext = new DataContext();
            var post_like_collection = dataContext.getConnection().GetCollection <Post_Like>("Post_Like");
            var filter = Builders <Post_Like> .Filter.Eq("_id", ObjectId.Parse(post_id));

            var update = Builders <Post_Like> .Update.AddToSet("like_records", like_Record);

            await post_like_collection.UpdateOneAsync(filter, update);
        }
Exemplo n.º 5
0
        public async Task update_like_record(string comment_id, Like_Record like_Record)
        {
            var comment_like_collection = dataContext.getConnection().GetCollection <Comment_Like>("Comment_Like");
            var filter = Builders <Comment_Like> .Filter.And(
                Builders <Comment_Like> .Filter.Where(x => x.comment_id == comment_id),
                Builders <Comment_Like> .Filter.Eq("like_records._id", ObjectId.Parse(like_Record._id)));

            var update = Builders <Comment_Like> .Update.Set("like_records.$.emoji", like_Record.emoji);

            await comment_like_collection.FindOneAndUpdateAsync(filter, update);
        }
Exemplo n.º 6
0
        public bool has_like(string comment_id, Like_Record like_Record)
        {
            var comment_like_collection = dataContext.getConnection().GetCollection <Comment_Like>("Comment_Like");
            var record = comment_like_collection.AsQueryable().Where(p => p.comment_id == comment_id).
                         SelectMany(c => c.like_Records).Where(p => p._id == like_Record._id).FirstOrDefault();

            if (record == null)
            {
                return(false);
            }
            return(true);
        }
        public async Task <IActionResult> post_like([FromBody] PostLike postLike)
        {
            if (ModelState.IsValid)
            {
                Owner       user_Session    = um.GetUser_Cookie(Request);
                string      decoded_post_id = _helper.DecodeFrom64(postLike.post_id);
                Like_Record like_Record     = new Like_Record
                {
                    emoji        = postLike.emo,
                    user_name    = user_Session.user_name,
                    user_picture = user_Session.user_picture,
                    _id          = user_Session._id
                };
                if (postLike.sub_post_id != null)
                {
                    await sub_post_like(decoded_post_id, _helper.DecodeFrom64(postLike.sub_post_id), postLike.emo, user_Session);
                }
                else
                {
                    PostLikeManagement plm = new PostLikeManagement();
                    if (plm.has_like(decoded_post_id, like_Record))
                    {
                        if (plm.get_like(decoded_post_id, user_Session._id) == postLike.emo)
                        {
                            await plm.remove_post_like_record(decoded_post_id, like_Record);

                            await plm.update_post_like_count(decoded_post_id, postLike.emo, -1);
                        }
                        else
                        {
                            await plm.update_post_like_count(decoded_post_id, plm.get_like(decoded_post_id, user_Session._id), -1);

                            await plm.update_post_like_count(decoded_post_id, postLike.emo, 1);

                            await plm.update_post_like_record(decoded_post_id, like_Record);
                        }
                    }
                    else
                    {
                        await plm.insertLikeRecord(decoded_post_id, like_Record);

                        await plm.update_post_like_count(decoded_post_id, postLike.emo, 1);
                    }
                }


                return(Ok());
            }
            else
            {
                return(BadRequest(new { Message = "Missing fields" }));
            }
        }
        public async Task <IActionResult> sub_comment_like([FromBody] SubCommentLike subCommentLike)
        {
            if (ModelState.IsValid)
            {
                Owner  user_Session    = um.GetUser_Cookie(Request);
                string decoded_post_id = _helper.DecodeFrom64(subCommentLike.post_id);
                if (subCommentLike.sub_post_id != null)
                {
                    decoded_post_id = _helper.DecodeFrom64(subCommentLike.sub_post_id);
                }
                string      decoded_comment_id = _helper.DecodeFrom64(subCommentLike.comment_id);
                Like_Record like_Record        = new Like_Record
                {
                    emoji        = subCommentLike.emo,
                    user_name    = user_Session.user_name,
                    user_picture = user_Session.user_picture,
                    _id          = user_Session._id
                };
                string decoded_sub_comment_id = _helper.DecodeFrom64(subCommentLike.sub_comment_id);
                if (clm.has_like(decoded_sub_comment_id, like_Record))
                {
                    if (clm.get_like(decoded_sub_comment_id, user_Session._id) == subCommentLike.emo)
                    {
                        await clm.remove_like_record(decoded_sub_comment_id, like_Record);

                        await clm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, subCommentLike.emo, -1);
                    }
                    else
                    {
                        await clm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, clm.get_like(decoded_sub_comment_id, user_Session._id), -1);

                        await clm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, subCommentLike.emo, 1);

                        await clm.update_like_record(decoded_sub_comment_id, like_Record);
                    }
                }
                else
                {
                    await clm.insertLikeRecord(decoded_sub_comment_id, like_Record);

                    await clm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, subCommentLike.emo, 1);
                }

                return(Ok());
            }
            else
            {
                return(BadRequest(new { Message = "Missing fields" }));
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> post_like(string post_id, string sub_post_id, string emo)
        {
            if (ModelState.IsValid)
            {
                Owner       user_Session    = um.GetUser_Session(Request);
                string      decoded_post_id = _helper.DecodeFrom64(post_id);
                Like_Record like_Record     = new Like_Record
                {
                    emoji        = emo,
                    user_name    = user_Session.user_name,
                    user_picture = user_Session.user_picture,
                    _id          = user_Session._id
                };
                PostLikeManagement plm = new PostLikeManagement();
                Debug.WriteLine(decoded_post_id);
                Debug.WriteLine(plm.has_like(decoded_post_id, like_Record));
                if (plm.has_like(decoded_post_id, like_Record))
                {
                    if (plm.get_like(decoded_post_id, user_Session._id) == emo)
                    {
                        await plm.remove_post_like_record(decoded_post_id, like_Record);

                        await plm.update_post_like_count(decoded_post_id, emo, -1);
                    }
                    else
                    {
                        await plm.update_post_like_count(decoded_post_id, plm.get_like(decoded_post_id, user_Session._id), -1);

                        await plm.update_post_like_count(decoded_post_id, emo, 1);

                        await plm.update_post_like_record(decoded_post_id, like_Record);
                    }
                }
                else
                {
                    await plm.insertLikeRecord(decoded_post_id, like_Record);

                    await plm.update_post_like_count(decoded_post_id, emo, 1);
                }

                return(Ok());
            }
            else
            {
                return(BadRequest(new { Message = "Missing fields" }));
            }
        }
Exemplo n.º 10
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> comment_like(string post_id, string comment_id, string sub_comment_id, string emo)
        {
            if (ModelState.IsValid)
            {
                Owner       user_Session       = um.GetUser_Session(Request);
                string      decoded_post_id    = _helper.DecodeFrom64(post_id);
                string      decoded_comment_id = _helper.DecodeFrom64(comment_id);
                Like_Record like_Record        = new Like_Record
                {
                    emoji        = emo,
                    user_name    = user_Session.user_name,
                    user_picture = user_Session.user_picture,
                    _id          = user_Session._id
                };
                if (sub_comment_id != null)
                {
                    string decoded_sub_comment_id = _helper.DecodeFrom64(sub_comment_id);
                    if (lm.has_like(decoded_sub_comment_id, like_Record))
                    {
                        if (lm.get_like(decoded_sub_comment_id, user_Session._id) == emo)
                        {
                            await lm.remove_like_record(decoded_sub_comment_id, like_Record);

                            await lm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, emo, -1);
                        }
                        else
                        {
                            await lm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, lm.get_like(decoded_sub_comment_id, user_Session._id), -1);

                            await lm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, emo, 1);

                            await lm.update_like_record(decoded_sub_comment_id, like_Record);
                        }
                    }
                    else
                    {
                        await lm.insertLikeRecord(decoded_sub_comment_id, like_Record);

                        await lm.update_sub_comment_likeAsync(decoded_post_id, decoded_comment_id, decoded_sub_comment_id, emo, 1);
                    }
                }
                else
                {
                    if (lm.has_like(decoded_comment_id, like_Record))
                    {
                        if (lm.get_like(decoded_comment_id, user_Session._id) == emo)
                        {
                            await lm.remove_like_record(decoded_comment_id, like_Record);

                            await lm.update_comment_likeAsync(decoded_post_id, decoded_comment_id, emo, -1);
                        }
                        else
                        {
                            await lm.update_comment_likeAsync(decoded_post_id, decoded_comment_id, lm.get_like(decoded_comment_id, user_Session._id), -1);

                            await lm.update_comment_likeAsync(decoded_post_id, decoded_comment_id, emo, 1);

                            await lm.update_like_record(decoded_comment_id, like_Record);
                        }
                    }
                    else
                    {
                        await lm.insertLikeRecord(decoded_comment_id, like_Record);

                        await lm.update_comment_likeAsync(decoded_post_id, decoded_comment_id, emo, 1);
                    }
                }
                return(Ok());
            }
            else
            {
                return(BadRequest(new { Message = "Missing fields" }));
            }
        }