summaryrefslogtreecommitdiff
path: root/CoreWiki/Models/Comment.cs
diff options
context:
space:
mode:
Diffstat (limited to 'CoreWiki/Models/Comment.cs')
-rw-r--r--CoreWiki/Models/Comment.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/CoreWiki/Models/Comment.cs b/CoreWiki/Models/Comment.cs
new file mode 100644
index 0000000..4f1026a
--- /dev/null
+++ b/CoreWiki/Models/Comment.cs
@@ -0,0 +1,55 @@
+using System.Buffers.Text;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Security.Cryptography;
+using System.Text;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualBasic;
+using NodaTime;
+using NodaTime.Extensions;
+
+namespace CoreWiki.Models;
+
+public class Comment
+{
+ public int Id { get; set; }
+ [Required]
+ public int ArticleId { get; set; }
+ [Required]
+ [DisplayName("Display Name")]
+ public string? DisplayName { get; set; }
+ [Required]
+ [DataType(DataType.EmailAddress)]
+ [DisplayName("E-Mail")]
+ public string? EMail { get; set; }
+ [NotMapped]
+ public string? GravatarHash
+ {
+ get
+ {
+ if (EMail == null)
+ {
+ return null;
+ }
+ var normalizedEmail = EMail.Trim().ToLower();
+ var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(normalizedEmail));
+ return BitConverter.ToString(bytes).Replace("-", "").ToLower();
+ }
+ }
+ [Required]
+ public string? Content { get; set; }
+ [NotMapped]
+ public Instant Submitted { get; set; }
+ [Obsolete("This property only exists for EF-serialization purposes")]
+ [DataType(DataType.DateTime)]
+ [Column("Submitted")]
+ public DateTime SubmittedDateTime
+ {
+ get => Submitted.ToDateTimeUtc();
+ // TODO: Remove this ugly hack
+ set => Submitted = DateTime.SpecifyKind(value, DateTimeKind.Utc).ToInstant();
+ }
+
+ public required Article Article { get; set; }
+} \ No newline at end of file