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

46 lines
1.1 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;
namespace TicketOffice.Pages.Management.Users
{
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 User User { get; set; }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.User.Add(User);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}
}
}