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);
            }
        }
Beispiel #2
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" }));
            }
        }
        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" }));
            }
        }