From 221a6f00076cef274d9bb82c4de7359cc468b2ca Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 10 Aug 2023 14:37:52 +0100 Subject: [PATCH] fix: add missing method from BlogService --- OliverBooth/Services/BlogService.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/OliverBooth/Services/BlogService.cs b/OliverBooth/Services/BlogService.cs index 8292e0f..c15dd83 100644 --- a/OliverBooth/Services/BlogService.cs +++ b/OliverBooth/Services/BlogService.cs @@ -61,7 +61,25 @@ public sealed class BlogService int moreIndex = span.IndexOf("", StringComparison.Ordinal); trimmed = moreIndex != -1 || span.Length > 256; string result = moreIndex != -1 ? span[..moreIndex].Trim().ToString() : post.Body.Truncate(256); - return RenderContent(result); + return RenderContent(result).Trim(); + } + + /// + /// Attempts to find the author by ID. + /// + /// The ID of the author. + /// + /// When this method returns, contains the associated with the specified ID, if the author + /// is found; otherwise, . + /// + /// if the author is found; otherwise, . + /// is . + public bool TryGetAuthor(int id, [NotNullWhen(true)] out Author? author) + { + using BlogContext context = _dbContextFactory.CreateDbContext(); + author = context.Authors.FirstOrDefault(a => a.Id == id); + + return author is not null; } /// @@ -71,6 +89,7 @@ public sealed class BlogService /// /// When this method returns, contains the associated with the specified blog post, if the /// author is found; otherwise, . + /// /// if the author is found; otherwise, . /// is . public bool TryGetAuthor(BlogPost post, [NotNullWhen(true)] out Author? author)