summaryrefslogtreecommitdiff
path: root/CoreWiki/Pages/Details.cshtml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'CoreWiki/Pages/Details.cshtml.cs')
-rw-r--r--CoreWiki/Pages/Details.cshtml.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/CoreWiki/Pages/Details.cshtml.cs b/CoreWiki/Pages/Details.cshtml.cs
new file mode 100644
index 0000000..25ff6c0
--- /dev/null
+++ b/CoreWiki/Pages/Details.cshtml.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Microsoft.EntityFrameworkCore;
+using CoreWiki.Models;
+
+namespace CoreWiki.Pages
+{
+ public class DetailsModel : PageModel
+ {
+ private readonly CoreWiki.Models.ApplicationDbContext _context;
+
+ public DetailsModel(CoreWiki.Models.ApplicationDbContext context)
+ {
+ _context = context;
+ }
+
+ public Article Article { get; set; } = default!;
+
+ public async Task<IActionResult> OnGetAsync(string? topicName)
+ {
+ topicName ??= "HomePage";
+
+ if (_context.Articles == null)
+ {
+ return NotFound();
+ }
+
+ var article = await _context.Articles.FirstOrDefaultAsync(m => m.Topic == topicName);
+ if (article == null)
+ {
+ return NotFound();
+ }
+ else
+ {
+ Article = article;
+ }
+ return Page();
+ }
+ }
+}