From 1a96616699ab41bf6343bc1acc45a836c3e6caf3 Mon Sep 17 00:00:00 2001 From: Paweł Bernaciak Date: Fri, 22 Dec 2023 16:02:41 +0100 Subject: Backup --- CoreWiki/Pages/Delete.cshtml.cs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'CoreWiki/Pages/Delete.cshtml.cs') 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 OnGetAsync(string id) + public async Task 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 OnPostAsync(string id) + public async Task 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("/"); } -- cgit v1.2.3