auto.bus_razor/TicketOffice/Pages/Management/Routes/Create.cshtml.cs

47 lines
1.2 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.AspNetCore.Mvc.Rendering;
using TicketOffice.Data;
using TicketOffice.Models;
using Route = TicketOffice.Models.Route;
namespace TicketOffice.Pages.Management.Routes
{
public class CreateModel : PageModel
{
private readonly TicketOffice.Data.TicketOfficeContext _context;
public CreateModel(TicketOffice.Data.TicketOfficeContext context)
{
_context = context;
}
public IActionResult OnGet()
{
return Page();
}
[BindProperty]
public Route Route { get; set; }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Route.Add(Route);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}
}
}