protected int GetCurrentUserVote(Post post) { string userId = this.User.Identity.GetUserId(); Like like = this.dbContext.Likes.FirstOrDefault(l => l.PostID == post.PostID && l.UserID == userId); if (like != null) { if (like.Value) { return 1; } else { return -1; } } else { return 0; } }
protected int GetLikesCount(Post post) { int likes = post.Likes.Count(p => p.Value == true); int hates = post.Likes.Count(p => p.Value == false); return likes - hates; }