Lieb-Website/Lieb/Pages/Users/Delete.cshtml.cs
2022-02-21 00:27:26 +01:00

60 lines
1.4 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 Lieb.Data;
using Lieb.Models;
namespace Lieb.Pages.Users
{
public class DeleteModel : PageModel
{
private readonly Lieb.Data.LiebContext _context;
public DeleteModel(Lieb.Data.LiebContext context)
{
_context = context;
}
[BindProperty]
public LiebUser User { get; set; }
public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null)
{
return NotFound();
}
User = await _context.Users.FirstOrDefaultAsync(m => m.LiebUserId == id);
if (User == null)
{
return NotFound();
}
return Page();
}
public async Task<IActionResult> OnPostAsync(int? id)
{
if (id == null)
{
return NotFound();
}
User = await _context.Users.FindAsync(id);
if (User != null)
{
_context.Users.Remove(User);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
}
}