62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
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 _2021_backend.Data;
|
|
using _2021_backend.Models;
|
|
|
|
namespace _2021_backend.Pages.Users
|
|
{
|
|
public class DeleteModel : PageModel
|
|
{
|
|
private readonly _2021_backend.Data.BackendContext _context;
|
|
|
|
public DeleteModel(_2021_backend.Data.BackendContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
[BindProperty]
|
|
public new User User { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(string id)
|
|
{
|
|
int idx = int.Parse(id);
|
|
if (id == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
User = _context.Users.Find(idx);
|
|
|
|
if (User == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(string id)
|
|
{
|
|
int idx = int.Parse(id);
|
|
if (id == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
User = _context.Users.Find(idx);
|
|
|
|
if (User != null)
|
|
{
|
|
_context.Users.Remove(User);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage("./Index");
|
|
}
|
|
}
|
|
}
|