Exemplo n.º 1
0
        public BlogPosts GetBlogPostsById(int id)
        {
            var blogPostsDto = new BlogPostsDto()
            {
                Blog = new BlogDto()
                {
                    Id  = 1234,
                    Url = "https://www.blogposts.com"
                },
                Posts = new List <PostDto>()
                {
                    new PostDto()
                    {
                        Id      = 1,
                        BlogId  = 1234,
                        Title   = "Complex model mapping",
                        Content = "Complex model mapping is easy"
                    },
                    new PostDto()
                    {
                        Id      = 2,
                        BlogId  = 1234,
                        Title   = "Complex model mapping",
                        Content = "Complex model mapping is hard"
                    }
                }
            };

            return(_mapper.Map <BlogPosts>(blogPostsDto));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetBlogPosts()
        {
            var blogPosts = await _repo.GetBlogPosts();

            var postCount = blogPosts.Count();

            BlogPostsDto blogPostsDto = new BlogPostsDto();

            blogPostsDto.BlogPosts = _mapper.Map <IEnumerable <BlogPostDto> >(blogPosts).ToList();
            blogPostsDto.PostCount = postCount;

            return(Ok(blogPostsDto));
        }