コード例 #1
0
        public UserPostBM GetUserPost(Guid postId)
        {
            using (var db = new DBContext())
            {
                var post   = db.UserPosts.FirstOrDefault(p => p.PostId.Equals(postId));
                var postBM = UserPostBM.From(post);

                postBM.LikeCount = db.UserLikes.Count(ul => ul.PostId.Equals(post.PostId));

                return(postBM);
            }
        }
コード例 #2
0
        private IList <UserPostBM> GetUserPost(IEnumerable <UserPost> posts, IEnumerable <UserLike> likes)
        {
            var userPosts = new List <UserPostBM>();

            foreach (var post in posts)
            {
                var postBM = UserPostBM.From(post);
                postBM.LikeCount = likes.Count(like => like.PostId.Equals(post.PostId));
                userPosts.Add(postBM);
            }

            return(userPosts);
        }