diff options
Diffstat (limited to 'CoreWiki/Models/Article.cs')
| -rw-r--r-- | CoreWiki/Models/Article.cs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/CoreWiki/Models/Article.cs b/CoreWiki/Models/Article.cs index b989573..31485e3 100644 --- a/CoreWiki/Models/Article.cs +++ b/CoreWiki/Models/Article.cs @@ -8,15 +8,13 @@ namespace CoreWiki.Models; public class Article { - [Key] - public string Slug { get; set; } - + public int Id { get; set; } + [Required] + public required string Slug { get; set; } [Required, MaxLength(100)] - public string Topic { get; set; } - + public string? Topic { get; set; } [NotMapped] public Instant Published { get; set; } = SystemClock.Instance.GetCurrentInstant(); - [Obsolete("This property is only for serialization")] [DataType(DataType.DateTime)] [Column("Published")] @@ -26,8 +24,26 @@ public class Article get => Published.ToDateTimeUtc(); set => Published = DateTime.SpecifyKind(value, DateTimeKind.Utc).ToInstant(); } - + [Required] + public required int ViewCount { get; set; } [DataType(DataType.MultilineText)] [Required] - public string Content { get; set; } = default!; + public string? Content { get; set; } + + [NotMapped] + public int? EstimatedReadingTime + { + get + { + if (Content == null) + { + return null; + } + var wpm = 275.00m; + var wordCount = Content.Split(" ").Length; + return (int)Math.Ceiling(wordCount / wpm); + } + } + + public ICollection<Comment> Comments { get; } = new List<Comment>(); }
\ No newline at end of file |
