From 79f5eaf40b93d64be74d8b4f1ef80d19fadbfbe1 Mon Sep 17 00:00:00 2001 From: Paweł Bernaciak Date: Fri, 29 Dec 2023 09:41:56 +0100 Subject: Cywilizowany tailwind --- CoreWiki/Models/Article.cs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'CoreWiki/Models/Article.cs') 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 Comments { get; } = new List(); } \ No newline at end of file -- cgit v1.2.3