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 EveryThing.Data; using EveryThing.Models; namespace EveryThing.Pages.Notes { public class DeleteModel : PageModel { private readonly EveryThing.Data.ApplicationDbContext _context; public DeleteModel(EveryThing.Data.ApplicationDbContext context) { _context = context; } [BindProperty] public GeneralNote Note { get; set; } public async Task OnGetAsync(int? id) { if (id == null) { return NotFound(); } Note = await _context.GeneralNotes .Include(n => n.Company) .Include(n => n.Employee) .Include(n => n.Vehicle).FirstOrDefaultAsync(m => m.IdNote == id); if (Note == null) { return NotFound(); } return Page(); } public async Task OnPostAsync(int? id) { if (id == null) { return NotFound(); } Note = await _context.GeneralNotes.FindAsync(id); if (Note != null) { _context.GeneralNotes.Remove(Note); await _context.SaveChangesAsync(); } return RedirectToPage("./Index"); } } }