auto.bus_razor/TicketOffice/Pages/Management/Tickets/Delete.cshtml.cs

63 lines
1.6 KiB
C#

#nullable disable
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 TicketOffice.Data;
using TicketOffice.Models;
namespace TicketOffice.Pages.Management.Tickets
{
public class DeleteModel : PageModel
{
private readonly TicketOffice.Data.TicketOfficeContext _context;
public DeleteModel(TicketOffice.Data.TicketOfficeContext context)
{
_context = context;
}
[BindProperty]
public Ticket Ticket { get; set; }
public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null)
{
return NotFound();
}
Ticket = await _context.Ticket
.Include(t => t.Route)
.Include(t => t.User).FirstOrDefaultAsync(m => m.Id == id);
if (Ticket == null)
{
return NotFound();
}
return Page();
}
public async Task<IActionResult> OnPostAsync(int? id)
{
if (id == null)
{
return NotFound();
}
Ticket = await _context.Ticket.FindAsync(id);
if (Ticket != null)
{
_context.Ticket.Remove(Ticket);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
}
}