Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BookStore.Domain/Entities/Auth/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class User : IdentityUser<Guid>
{
public string FullName { get; set; }
public string? PhotoPath { get; set; }
public bool? Check { get; set; } = false;
}
}
43 changes: 41 additions & 2 deletions src/BookStore.Presentation/MVC/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
@@ -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<User> _userManager;


public AdminController(UserManager<User> userManager)
{

_userManager = userManager;
}

public IActionResult Index()
{
return View();
var users = _userManager.Users.Where(x => x.Check == false).ToList();
return View(users);
}

public async Task<IActionResult> 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<IActionResult> 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");
}
}
}
26 changes: 25 additions & 1 deletion src/BookStore.Presentation/MVC/Views/Admin/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
Qales Admin
@using BookStore.Domain.Entities.Auth
@model List<User>
<table class="table">
<thead>
<tr>
<th scope="col">Username</th>
<th scope="col">Email</th>
<th scope="col">PhoneNumber</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach(var user in Model)
{
<tr>
<td>@user.UserName</td>
<td>@user.Email</td>
<td>@user.PhoneNumber</td>
<td><a asp-controller="Admin" asp-action="UpdateAdmin" asp-route-id="@user.Id" class="btn btn-success">Admin</a></td>
<td><a asp-controller="Admin" asp-action="UpdateUser" asp-route-id="@user.Id" class="btn btn-danger">Ignor</a></td>
</tr>
}
</tbody>
</table>