From 7fefe217c8462444ecb9806599e70afe2a7102ea Mon Sep 17 00:00:00 2001 From: Paweł Bernaciak Date: Fri, 10 Feb 2023 21:24:11 +0100 Subject: Time display fixes --- CoreWiki/Pages/Create.cshtml.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'CoreWiki/Pages/Create.cshtml.cs') diff --git a/CoreWiki/Pages/Create.cshtml.cs b/CoreWiki/Pages/Create.cshtml.cs index ccde2ff..d89b97b 100644 --- a/CoreWiki/Pages/Create.cshtml.cs +++ b/CoreWiki/Pages/Create.cshtml.cs @@ -6,16 +6,19 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using CoreWiki.Models; +using NodaTime; namespace CoreWiki.Pages { public class CreateModel : PageModel { private readonly CoreWiki.Models.ApplicationDbContext _context; + private readonly IClock _clock; - public CreateModel(CoreWiki.Models.ApplicationDbContext context) + public CreateModel(CoreWiki.Models.ApplicationDbContext context, IClock clock) { _context = context; + _clock = clock; } public IActionResult OnGet() @@ -25,16 +28,17 @@ namespace CoreWiki.Pages [BindProperty] public Article Article { get; set; } = default!; - + // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task OnPostAsync() { - if (!ModelState.IsValid || _context.Articles == null || Article == null) + if (!ModelState.IsValid || _context.Articles == null || Article == null) { return Page(); } + Article.Published = _clock.GetCurrentInstant(); _context.Articles.Add(Article); await _context.SaveChangesAsync(); -- cgit v1.2.3