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); } }
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> 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 List <Post> getVideoImage(string post_id, string sub_post_id) { Owner owner = um.GetUser_Cookie(Request); string decoded_post_id = helper.DecodeFrom64(post_id); string decoded_sub_post_id = helper.DecodeFrom64(sub_post_id); Post post = pm.GetVideoImages(decoded_post_id, decoded_sub_post_id); User u = um.GetUser_Detail(post.owner._id); post.owner.user_name = u.first_name + " " + u.last_name; post.owner.user_picture = u.profile_img; PostLikeManagement plm = new PostLikeManagement(); foreach (Post p in post.video_image) { p.has_like = plm.get_like(p._id, owner._id); if (p._id != null) { p._id = helper.EncodeTo64(p._id); } p.no_of_comment = (int)Math.Ceiling(p.comments * 1.0 / 5); } return(post.video_image); }