using System.ComponentModel.DataAnnotations.Schema; using SmartFormat; namespace OliverBooth.Data.Blog; /// internal sealed class BlogPostDraft : IBlogPostDraft { /// [NotMapped] public IBlogAuthor Author { get; internal set; } = null!; /// public string Body { get; set; } = string.Empty; /// public bool EnableComments { get; internal set; } /// public Guid Id { get; private set; } = Guid.NewGuid(); /// public bool IsRedirect { get; internal set; } /// public string? Password { get; internal set; } /// public Uri? RedirectUrl { get; internal set; } /// public string Slug { get; internal set; } = string.Empty; /// public IReadOnlyList Tags { get; internal set; } = ArraySegment.Empty; /// public string Title { get; set; } = string.Empty; /// public DateTimeOffset Updated { get; internal set; } /// public BlogPostVisibility Visibility { get; internal set; } /// public int? WordPressId { get; set; } /// /// Gets or sets the ID of the author of this blog post. /// /// The ID of the author of this blog post. internal Guid AuthorId { get; set; } /// /// Gets or sets the base URL of the Disqus comments for the blog post. /// /// The Disqus base URL. internal string? DisqusDomain { get; set; } /// /// Gets or sets the identifier of the Disqus comments for the blog post. /// /// The Disqus identifier. internal string? DisqusIdentifier { get; set; } /// /// Gets or sets the URL path of the Disqus comments for the blog post. /// /// The Disqus URL path. internal string? DisqusPath { get; set; } /// /// Constructs a by copying values from an existing . /// /// The existing . /// The newly-constructed . /// is . public static BlogPostDraft CreateFromBlogPost(BlogPost post) { if (post is null) { throw new ArgumentNullException(nameof(post)); } return new BlogPostDraft { AuthorId = post.AuthorId, Body = post.Body, DisqusDomain = post.DisqusDomain, DisqusIdentifier = post.DisqusIdentifier, DisqusPath = post.DisqusPath, EnableComments = post.EnableComments, IsRedirect = post.IsRedirect, Password = post.Password, RedirectUrl = post.RedirectUrl, Tags = post.Tags, Title = post.Title, Visibility = post.Visibility, WordPressId = post.WordPressId }; } /// /// Gets the Disqus domain for the blog post. /// /// The Disqus domain. public string GetDisqusDomain() { return string.IsNullOrWhiteSpace(DisqusDomain) ? "https://oliverbooth.dev/blog" : Smart.Format(DisqusDomain, this); } /// public string GetDisqusIdentifier() { return string.IsNullOrWhiteSpace(DisqusIdentifier) ? $"post-{Id}" : Smart.Format(DisqusIdentifier, this); } /// public string GetDisqusPostId() { return WordPressId?.ToString() ?? Id.ToString(); } }