45 lines
1 KiB
C#
45 lines
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 Lieb.Data;
|
|
using Lieb.Models;
|
|
|
|
namespace Lieb.Pages.Users
|
|
{
|
|
public class CreateModel : PageModel
|
|
{
|
|
private readonly Lieb.Data.LiebContext _context;
|
|
|
|
public CreateModel(Lieb.Data.LiebContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IActionResult OnGet()
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
[BindProperty]
|
|
public LiebUser User { get; set; }
|
|
|
|
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
_context.Users.Add(User);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return RedirectToPage("./Index");
|
|
}
|
|
}
|
|
}
|