diff options
Diffstat (limited to 'CoreWiki/Pages/Create.cshtml.cs')
| -rw-r--r-- | CoreWiki/Pages/Create.cshtml.cs | 10 |
1 files changed, 7 insertions, 3 deletions
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<IActionResult> 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();
|
