示例#1
0
        public async Task <IActionResult> GetAll()
        {
            var data = await _repo.GetAll();

            List <PostResponseDTO> postListToReturn = new List <PostResponseDTO>();

            foreach (var item in data)
            {
                PostResponseDTO postToReturn = new PostResponseDTO();

                postToReturn.PostContent  = item.PostContent;
                postToReturn.CreationTime = item.PostCreationTime;
                postToReturn.UserName     = await _repo.GetUserName(item.UserId);

                postToReturn.TotalComments = await _repo.GetTotalComment(item.Id);

                var comm = await _repo.GetComments(item.Id);

                List <CommentDTO> commentList = new List <CommentDTO>();

                foreach (var x in comm)
                {
                    CommentDTO c = new CommentDTO();

                    c.CommentContent = x.CommentContent;
                    c.CreationTime   = x.CommentCreationTime;
                    c.UserName       = await _repo.GetUserName(x.UserId);

                    c.TotalLikes = await _repo.FindTotalLike(x.Id, x.UserId);

                    c.TotalDisLikes = await _repo.FindTotalDisLike(x.Id, x.UserId);

                    commentList.Add(c);
                }

                postToReturn.Comments = commentList;

                postListToReturn.Add(postToReturn);
            }

            return(Ok(postListToReturn));
        }
 // GET: News
 public IActionResult Index()
 {
     return(View(_PostRepo.GetAll()));
 }
 public List <Posts> GetAllPost()
 {
     return(_postRepo.GetAll());
 }
示例#4
0
 public List <Post> Get()
 {
     return(_post.GetAll());
 }