summaryrefslogtreecommitdiff
path: root/CoreWiki/Pages/Delete.cshtml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'CoreWiki/Pages/Delete.cshtml.cs')
-rw-r--r--CoreWiki/Pages/Delete.cshtml.cs33
1 files changed, 15 insertions, 18 deletions
diff --git a/CoreWiki/Pages/Delete.cshtml.cs b/CoreWiki/Pages/Delete.cshtml.cs
index 9de563e..584dc48 100644
--- a/CoreWiki/Pages/Delete.cshtml.cs
+++ b/CoreWiki/Pages/Delete.cshtml.cs
@@ -19,42 +19,39 @@ namespace CoreWiki.Pages
}
[BindProperty]
- public Article Article { get; set; } = default!;
+ public Article Article { get; set; } = default!;
- public async Task<IActionResult> OnGetAsync(string id)
+ public async Task<IActionResult> OnGetAsync(string slug)
{
- if (id == null || _context.Articles == null)
+ if (slug == "home-page")
{
return NotFound();
}
-
- var article = await _context.Articles.FirstOrDefaultAsync(m => m.Topic == id);
+
+ var article = await _context.Articles.FirstOrDefaultAsync(a => a.Slug == slug);
if (article == null)
{
return NotFound();
}
- else
- {
- Article = article;
- }
+
+ Article = article;
return Page();
}
- public async Task<IActionResult> OnPostAsync(string id)
+ public async Task<IActionResult> OnPostAsync(string slug)
{
- if (id == null || _context.Articles == null)
+ if (slug == "home-page")
{
return NotFound();
}
- var article = await _context.Articles.FindAsync(id);
+
+ var article = await _context.Articles.FirstOrDefaultAsync(a => a.Slug == slug);
- if (article != null)
- {
- Article = article;
- _context.Articles.Remove(Article);
- await _context.SaveChangesAsync();
- }
+ if (article == null) return NotFound();
+ Article = article;
+ _context.Articles.Remove(Article);
+ await _context.SaveChangesAsync();
return Redirect("/");
}