Ejemplo n.º 1
0
        public CategoryResponseDto GetCategoryById(int Id)
        {
            var category = GetById(Id);

            var listOfPost     = new List <PostResponseDto>();
            var listOfImages   = new List <ImageResponseDto>();
            var listOfComments = new List <CommentResponseDto>();


            foreach (var post in category.Posts)
            {
                foreach (var comment in post.Comments)
                {
                    var commentDto = new CommentResponseDto
                    {
                        Id = comment.Id,
                        ContentOfComment = comment.Content,
                        postId           = comment.postId
                    };
                    listOfComments.Add(commentDto);
                }

                foreach (var image in post.Images)
                {
                    var imageDto = new ImageResponseDto
                    {
                        Id        = image.Id,
                        Name      = image.Name,
                        Url       = image.Url,
                        Extension = image.Extension,
                        postId    = image.postId
                    };
                    listOfImages.Add(imageDto);
                }

                var postDto = new PostResponseDto
                {
                    Id         = post.Id,
                    Title      = post.Title,
                    Content    = post.Content,
                    Likes      = post.Likes,
                    Dislikes   = post.Dislikes,
                    Comments   = listOfComments,
                    Images     = listOfImages,
                    CategoryId = post.CategoryId
                };

                listOfPost.Add(postDto);
            }


            var categoryDto = new CategoryResponseDto
            {
                Id    = category.Id,
                Name  = category.Name,
                Posts = listOfPost
            };

            return(categoryDto);
        }
Ejemplo n.º 2
0
        public List <PostResponseDto> GetAllPost()
        {
            var posts = _context.Posts.Include("Images").Include("Comments").ToList();

            posts.Reverse();
            var listOfPost     = new List <PostResponseDto>();
            var listOfImages   = new List <ImageResponseDto>();
            var listOfComments = new List <CommentResponseDto>();

            foreach (var post in posts)
            {
                if (post.Comments.Count != 0)
                {
                    foreach (var comment in post.Comments)
                    {
                        var commentDto = new CommentResponseDto
                        {
                            Id = comment.Id,
                            ContentOfComment = comment.Content,
                            postId           = comment.postId
                        };
                        listOfComments.Add(commentDto);
                    }
                }

                if (post.Images.Count != 0)
                {
                    foreach (var image in post.Images)
                    {
                        var imageDto = new ImageResponseDto
                        {
                            Id        = image.Id,
                            Name      = image.Name,
                            Url       = image.Url,
                            Extension = image.Extension,
                            postId    = image.postId
                        };
                        listOfImages.Add(imageDto);
                    }
                }

                var postDto = new PostResponseDto
                {
                    Id       = post.Id,
                    Title    = post.Title,
                    Content  = post.Content,
                    Likes    = post.Likes,
                    Dislikes = post.Dislikes,
                    //Comments = listOfComments,
                    Images     = listOfImages,
                    CategoryId = post.CategoryId
                };

                listOfPost.Add(postDto);
            }

            return(listOfPost);
        }
Ejemplo n.º 3
0
        public ActionResult <CommentResponseDto> GetCommentByCommentId(int id)
        {
            CommentResponseDto comment = _service.GetCommentById(id);

            if (comment != null)
            {
                return(Ok(comment));
            }

            return(NotFound());
        }
Ejemplo n.º 4
0
        public CommentResponseDto GetCommentById(int Id)
        {
            var comment    = GetById(Id);
            var commentDto = new CommentResponseDto
            {
                Id = comment.Id,
                ContentOfComment = comment.Content,
                postId           = comment.postId
            };

            return(commentDto);
        }
Ejemplo n.º 5
0
        public List <CommentResponseDto> GetAllComment()
        {
            var listOfComments = new List <CommentResponseDto>();
            var comments       = GetAll();

            foreach (var comment in comments)
            {
                var commentDto = new CommentResponseDto
                {
                    Id = comment.Id,
                    ContentOfComment = comment.Content,
                    postId           = comment.postId
                };
                listOfComments.Add(commentDto);
            }

            return(listOfComments);
        }