47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using MTG_CollectionVerwaltung.Data;
|
|
using MTG_CollectionVerwaltung.Data.MTGCollection;
|
|
|
|
namespace MTG_CollectionVerwaltung.Areas.Identity.Pages.Account.Admin
|
|
{
|
|
[Authorize(Roles = "Admin")]
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
|
private readonly SignInManager<ApplicationUser> _signInManager;
|
|
|
|
public IndexModel(
|
|
UserManager<ApplicationUser> userManager,
|
|
SignInManager<ApplicationUser> signInManager)
|
|
{
|
|
_userManager = userManager;
|
|
_signInManager = signInManager;
|
|
}
|
|
|
|
public List<ApplicationUser> Users { get; set; } = new List<ApplicationUser>();
|
|
|
|
public string? CurrentUserID { get; set; }
|
|
|
|
public void OnGet()
|
|
{
|
|
Users = _userManager.Users.ToList();
|
|
CurrentUserID = _userManager.GetUserId(User);
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteAsync(string userId)
|
|
{
|
|
var user = await _userManager.FindByIdAsync(userId);
|
|
if (user != null)
|
|
{
|
|
if(userId != CurrentUserID)
|
|
await _userManager.DeleteAsync(user);
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
}
|
|
}
|