blob: 31485e37d47e8a9f1617f74732af99d302ebf9c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
using NodaTime;
using NodaTime.Extensions;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CoreWiki.Utils;
namespace CoreWiki.Models;
public class Article
{
public int Id { get; set; }
[Required]
public required string Slug { get; set; }
[Required, MaxLength(100)]
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")]
[Required]
public DateTime PublishedDateTime
{
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; }
[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>();
}
|