diff options
Diffstat (limited to 'CoreWiki/Pages')
| -rw-r--r-- | CoreWiki/Pages/Create.cshtml.cs | 10 | ||||
| -rw-r--r-- | CoreWiki/Pages/Details.cshtml | 3 | ||||
| -rw-r--r-- | CoreWiki/Pages/Edit.cshtml.cs | 6 | ||||
| -rw-r--r-- | CoreWiki/Pages/LatestChanges.cshtml | 2 | ||||
| -rw-r--r-- | CoreWiki/Pages/LatestChanges.cshtml.cs | 2 | ||||
| -rw-r--r-- | CoreWiki/Pages/Shared/_Layout.cshtml | 3 |
6 files changed, 18 insertions, 8 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();
diff --git a/CoreWiki/Pages/Details.cshtml b/CoreWiki/Pages/Details.cshtml index 5ef6460..bf1a616 100644 --- a/CoreWiki/Pages/Details.cshtml +++ b/CoreWiki/Pages/Details.cshtml @@ -6,7 +6,7 @@ }
<h1>@Model.Article.Topic</h1>
-<h5>Last Published: @Model.Article.Published.ToShortDateString()</h5>
+<h5>Last Published: <span data-value="@Model.Article.Published" class="timeStampValue">@Model.Article.Published</span></h5>
<markdown markdown="Article.Content"/>
@@ -17,3 +17,4 @@ <text>| </text> <a href="~/">Back to Home</a>
}
</div>
+
diff --git a/CoreWiki/Pages/Edit.cshtml.cs b/CoreWiki/Pages/Edit.cshtml.cs index 06d002f..e3b11c2 100644 --- a/CoreWiki/Pages/Edit.cshtml.cs +++ b/CoreWiki/Pages/Edit.cshtml.cs @@ -7,16 +7,19 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using CoreWiki.Models;
+using NodaTime;
namespace CoreWiki.Pages
{
public class EditModel : PageModel
{
private readonly CoreWiki.Models.ApplicationDbContext _context;
+ private readonly IClock _clock;
- public EditModel(CoreWiki.Models.ApplicationDbContext context)
+ public EditModel(CoreWiki.Models.ApplicationDbContext context, IClock clock)
{
_context = context;
+ _clock = clock;
}
[BindProperty]
@@ -48,6 +51,7 @@ namespace CoreWiki.Pages }
_context.Attach(Article).State = EntityState.Modified;
+ Article.Published = _clock.GetCurrentInstant();
try
{
diff --git a/CoreWiki/Pages/LatestChanges.cshtml b/CoreWiki/Pages/LatestChanges.cshtml index 6a49022..390c8ab 100644 --- a/CoreWiki/Pages/LatestChanges.cshtml +++ b/CoreWiki/Pages/LatestChanges.cshtml @@ -16,7 +16,7 @@ <div class="card border-primary m-1">
<div class="card-body">
<h3 class="card-title"><a href="~/@item.Topic">@item.Topic</a></h3>
- <h6 class="card-subtitle mb-2 text-muted">@item.Published.ToShortDateString()</h6>
+ <h6 class="card-subtitle mb-2 text-muted"><span data-value="@item.Published" class="timeStampValue">@item.Published</span></h6>
<a class="card-link" asp-page="./Edit" asp-route-id="@item.Topic">Edit</a>
<a class="card-link" asp-page="./Delete" asp-route-id="@item.Topic">Delete</a>
diff --git a/CoreWiki/Pages/LatestChanges.cshtml.cs b/CoreWiki/Pages/LatestChanges.cshtml.cs index d750417..83a70ab 100644 --- a/CoreWiki/Pages/LatestChanges.cshtml.cs +++ b/CoreWiki/Pages/LatestChanges.cshtml.cs @@ -24,7 +24,7 @@ namespace CoreWiki.Pages {
if (_context.Articles != null)
{
- Article = await _context.Articles.OrderByDescending(a => a.Published).Take(10).ToListAsync();
+ Article = await _context.Articles.OrderByDescending(a => a.PublishedDateTime).Take(10).ToListAsync();
}
}
}
diff --git a/CoreWiki/Pages/Shared/_Layout.cshtml b/CoreWiki/Pages/Shared/_Layout.cshtml index 6376153..dbe5e47 100644 --- a/CoreWiki/Pages/Shared/_Layout.cshtml +++ b/CoreWiki/Pages/Shared/_Layout.cshtml @@ -7,6 +7,7 @@ <link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.min.css"/> <link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/> <link rel="stylesheet" href="~/CoreWiki.styles.css" asp-append-version="true"/> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" /> @await RenderSectionAsync("Styles", required: false) </head> <body> @@ -48,7 +49,7 @@ <script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/bootstrap/js/bootstrap.bundle.min.js"></script> -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" /> +<script src="~/lib/momentjs/moment.min.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> @await RenderSectionAsync("Scripts", required: false) |
