diff --git a/src/BookStore.Domain/Entities/Auth/User.cs b/src/BookStore.Domain/Entities/Auth/User.cs index 777f37b..709254b 100644 --- a/src/BookStore.Domain/Entities/Auth/User.cs +++ b/src/BookStore.Domain/Entities/Auth/User.cs @@ -6,5 +6,6 @@ public class User : IdentityUser { public string FullName { get; set; } public string? PhotoPath { get; set; } + public bool? Check { get; set; } = false; } } diff --git a/src/BookStore.Presentation/MVC/Controllers/AdminController.cs b/src/BookStore.Presentation/MVC/Controllers/AdminController.cs index df89057..ce95087 100644 --- a/src/BookStore.Presentation/MVC/Controllers/AdminController.cs +++ b/src/BookStore.Presentation/MVC/Controllers/AdminController.cs @@ -1,12 +1,51 @@ -using Microsoft.AspNetCore.Mvc; +using BookStore.Application.Abstractions; +using BookStore.Domain.Entities.Auth; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; namespace MVC.Controllers { public class AdminController : Controller { + private readonly UserManager _userManager; + + + public AdminController(UserManager userManager) + { + + _userManager = userManager; + } + public IActionResult Index() { - return View(); + var users = _userManager.Users.Where(x => x.Check == false).ToList(); + return View(users); + } + + public async Task UpdateUser(Guid Id) + { + var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == Id); + if(user == null) + { + throw new Exception("User is null"); + } + user.Check = true; + await _userManager.UpdateAsync(user); + return RedirectToAction("Index"); + } + public async Task UpdateAdmin(Guid Id) + { + var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == Id); + if(user == null) + { + throw new Exception("User is null"); + } + user.Check = true; + await _userManager.RemoveFromRoleAsync(user,"User"); + await _userManager.AddToRoleAsync(user, "Admin"); + await _userManager.UpdateAsync(user); + return RedirectToAction("Index"); } } } diff --git a/src/BookStore.Presentation/MVC/Views/Admin/Index.cshtml b/src/BookStore.Presentation/MVC/Views/Admin/Index.cshtml index 18d327b..77ec447 100644 --- a/src/BookStore.Presentation/MVC/Views/Admin/Index.cshtml +++ b/src/BookStore.Presentation/MVC/Views/Admin/Index.cshtml @@ -1 +1,25 @@ -Qales Admin \ No newline at end of file +@using BookStore.Domain.Entities.Auth +@model List + + + + + + + + + + + + @foreach(var user in Model) + { + + + + + + + + } + +
UsernameEmailPhoneNumber
@user.UserName@user.Email@user.PhoneNumberAdminIgnor
\ No newline at end of file