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)); }
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)); }