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 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 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("/"); } } }