summaryrefslogtreecommitdiff
path: root/CoreWiki/Models
diff options
context:
space:
mode:
authorPaweł Bernaciak <pawelbernaciak@zohomail.eu>2023-12-22 16:02:41 +0100
committerPaweł Bernaciak <pawelbernaciak@zohomail.eu>2023-12-22 16:02:41 +0100
commit1a96616699ab41bf6343bc1acc45a836c3e6caf3 (patch)
treeaff3d8bb8418355d3a8279024afaa13f196a0506 /CoreWiki/Models
parent7fefe217c8462444ecb9806599e70afe2a7102ea (diff)
Backup
Diffstat (limited to 'CoreWiki/Models')
-rw-r--r--CoreWiki/Models/ApplicationDbContext.cs9
-rw-r--r--CoreWiki/Models/Article.cs13
2 files changed, 19 insertions, 3 deletions
diff --git a/CoreWiki/Models/ApplicationDbContext.cs b/CoreWiki/Models/ApplicationDbContext.cs
index 48b5dcf..38c3787 100644
--- a/CoreWiki/Models/ApplicationDbContext.cs
+++ b/CoreWiki/Models/ApplicationDbContext.cs
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
+using NodaTime;
namespace CoreWiki.Models;
@@ -8,7 +9,13 @@ public class ApplicationDbContext : DbContext
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
-
}
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+ modelBuilder.Entity<Article>().HasData(
+ new Article { Topic = "Home Page", Slug = "home-page", Content = "Welcome to your new CoreWiki installation" }
+ );
+ }
} \ No newline at end of file
diff --git a/CoreWiki/Models/Article.cs b/CoreWiki/Models/Article.cs
index 53c2706..b989573 100644
--- a/CoreWiki/Models/Article.cs
+++ b/CoreWiki/Models/Article.cs
@@ -2,23 +2,32 @@ using NodaTime;
using NodaTime.Extensions;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using CoreWiki.Utils;
namespace CoreWiki.Models;
public class Article
{
- [Required, Key]
+ [Key]
+ public 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();
}
+
[DataType(DataType.MultilineText)]
- public string Content { get; set; }
+ [Required]
+ public string Content { get; set; } = default!;
} \ No newline at end of file