/// <summary> /// This method increment number of likes of post. /// </summary> /// <param name="post">Post to be liked.</param> public void LikePost(vwFriendPost post, vwUser userWhoLikePost) { try { using (BetweenUsEntities context = new BetweenUsEntities()) { int id = context.vwFriendPosts.Where(x => x.PostId == post.PostId).Select(x => x.PostId).FirstOrDefault(); tblPost postToLike = context.tblPosts.Where(x => x.PostId == id).FirstOrDefault(); if (postToLike != null) { postToLike.NumberOfLikes++; context.SaveChanges(); } tblLikedPost likedPost = new tblLikedPost { UserId = userWhoLikePost.UserId, PostId = postToLike.PostId }; context.tblLikedPosts.Add(likedPost); context.SaveChanges(); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public bool IsUserLikedPost(vwFriendPost post, vwUser user) { try { using (BetweenUsEntities context = new BetweenUsEntities()) { tblLikedPost likedPost = context.tblLikedPosts.Where(x => x.PostId == post.PostId && x.UserId == user.UserId).FirstOrDefault(); if (likedPost != null) { return(true); } else { return(false); } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }