public UserComments GetUserComments(int id) { User user = this.userRepository.GetById(id); var posts = this.postRepository.GetPostsByUserId(user.Id); IList <Comment> comments = this.commentRepository.GetAll(); IEnumerable <int> postsB = from post in posts select post.Id; // IList<int> postsB = posts.Select(u => u.Id).ToList(); var comm = from comment in comments where postsB.Contains(comment.PostId) select comment; UserComments result = new UserComments { User = user, Comments = comm.ToList(), }; return(result); }
public UserComments GetUserComments(int id) { var user = this.userRepository.GetById(id); var comments = this.commentRepository.GetAll(); var response = new UserComments { User = user, Comments = comments.Where(c => c.UserId == user.Id).ToList() }; return(response); }
public UserComments GetCommentsPerUser(int id) { var comments = new UserComments(); var user = this.userRepository.GetById(id); comments.Name = user.Name; var comms = this.commentRepository.GetCommentsByUserId(user.Id); foreach (var comm in comms) { comments.Comments.Add(comm.Id, comm.Text); } return(comments); }
public List <UserComments> GetUserComents(int id) { var comments = new List <UserComments>(); var comment = new UserComments(); var userComment = this.commentRepository.GetCommentByUserId(id); foreach (var item in userComment) { comment.Comment = item.Text; comments.Add(comment); } return(comments); }