public BlogPost Get(BlogPostId id) { if (_blogPostRepository.BlogPosts.TryGetValue(id, out var post)) { return(post); } throw new InvalidOperationException("Blog post not found"); }
public BlogPostRepository() { var blogPosts = new Dictionary <BlogPostId, BlogPost>(); var b1 = new BlogPostId(Guid.Parse("1B22072E-F3F1-445B-98C3-6CD4E21E5B12")); var b2 = new BlogPostId(Guid.Parse("DE9BEE94-39CB-4BE9-A021-82354AAAF3D3")); blogPosts[b1] = new BlogPost(b1, "Fancy content"); blogPosts[b2] = new BlogPost(b2, "Even fancier content"); BlogPosts = blogPosts.ToImmutableDictionary(); }
public ActionResult <string> Get(BlogPostId id) { ActionResult <string> result; try { var blogPost = _blogPostService.Get(id); result = Ok(blogPost.Content); } catch (InvalidOperationException e) { _logger.LogInformation(e, "Blog post (id: {0}) not found", id); result = NotFound(id); } return(result); }
public override int GetHashCode() { return(BlogPostId.GetHashCode()); }
public BlogPost(BlogPostId id, string content) { Id = id; Content = content; }