summaryrefslogtreecommitdiff
path: root/CoreWiki/Pages/Delete.cshtml.cs
diff options
context:
space:
mode:
authorPaweł Bernaciak <pawelbernaciak@zohomail.eu>2023-02-10 16:19:46 +0100
committerPaweł Bernaciak <pawelbernaciak@zohomail.eu>2023-02-10 16:19:46 +0100
commit00c3b32e2db200a2f42396ac7f8381704ec97268 (patch)
tree089d68dcbda127d4c95ccca9b0c9a18b59dc8bdc /CoreWiki/Pages/Delete.cshtml.cs
Initial Commit
Diffstat (limited to 'CoreWiki/Pages/Delete.cshtml.cs')
-rw-r--r--CoreWiki/Pages/Delete.cshtml.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/CoreWiki/Pages/Delete.cshtml.cs b/CoreWiki/Pages/Delete.cshtml.cs
new file mode 100644
index 0000000..9de563e
--- /dev/null
+++ b/CoreWiki/Pages/Delete.cshtml.cs
@@ -0,0 +1,62 @@
+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 DeleteModel : PageModel
+ {
+ private readonly CoreWiki.Models.ApplicationDbContext _context;
+
+ public DeleteModel(CoreWiki.Models.ApplicationDbContext context)
+ {
+ _context = context;
+ }
+
+ [BindProperty]
+ public Article Article { get; set; } = default!;
+
+ public async Task<IActionResult> OnGetAsync(string id)
+ {
+ if (id == null || _context.Articles == null)
+ {
+ return NotFound();
+ }
+
+ var article = await _context.Articles.FirstOrDefaultAsync(m => m.Topic == id);
+
+ if (article == null)
+ {
+ return NotFound();
+ }
+ else
+ {
+ Article = article;
+ }
+ return Page();
+ }
+
+ public async Task<IActionResult> OnPostAsync(string id)
+ {
+ if (id == null || _context.Articles == null)
+ {
+ return NotFound();
+ }
+ var article = await _context.Articles.FindAsync(id);
+
+ if (article != null)
+ {
+ Article = article;
+ _context.Articles.Remove(Article);
+ await _context.SaveChangesAsync();
+ }
+
+ return Redirect("/");
+ }
+ }
+}