本文整理汇总了C#中IBlogRepository.GetBlogWithEntries方法的典型用法代码示例。如果您正苦于以下问题:C# IBlogRepository.GetBlogWithEntries方法的具体用法?C# IBlogRepository.GetBlogWithEntries怎么用?C# IBlogRepository.GetBlogWithEntries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBlogRepository
的用法示例。
在下文中一共展示了IBlogRepository.GetBlogWithEntries方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BlogModule
public BlogModule(IBlogRepository repository) : base("/blogs")
{
Get["/"] = _ =>
{
IEnumerable<Blog> blogs = repository.GetBlogs();
return Response.AsJson(blogs.Select((bp, index) => new BlogDto
{
Description = bp.Description,
Title = bp.Title,
Url = bp.Url,
Id = index
})).AsCacheable(DateTime.Now.AddHours(12));
};
Get["/{id}"] = args =>
{
Blog blog = repository.GetBlogWithEntries(args.id);
var posts = blog.Entries.Select((bp, index) =>
new BlogPostOverviewDto
{
Author = bp.AuthorName,
Description = bp.Description,
Id = index,
Published = bp.PublishedDate,
Title = bp.Title,
ThumbnailUrl = bp.ThumbnailUrl,
Url = bp.Url
});
return Response.AsJson(new BlogWithPostsDto
{
Id = args.id,
Description = blog.Description,
Title = blog.Title,
Url = blog.Url,
Posts = posts.ToArray()
}).AsCacheable(DateTime.Now.AddHours(3));
};
Get["/{id}/{postId}"] = args =>
{
Blog blog = repository.GetBlogWithEntries(args.id);
BlogEntry correctEntry = Enumerable.ElementAt(blog.Entries, args.postId);
return Response.AsJson(new BlogPostDto()
{
Author = correctEntry.AuthorName,
Title = correctEntry.Title,
Content = correctEntry.Content,
BlogId = args.id,
Id = args.postId,
Published = correctEntry.PublishedDate
}).AsCacheable(DateTime.Now.AddHours(3));
};
}