Skip to content

Commit 32584f0

Browse files
Admin area, logs, roles, users controller added. Seed data added for module Logs. Side bar connected with DB added. It is full function according to categories, module, functions and user role management.
1 parent 43ea983 commit 32584f0

File tree

14 files changed

+314
-29
lines changed

14 files changed

+314
-29
lines changed

ApiIntegrationMvc/ApiIntegrationMvc.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14+
<Folder Include="Areas\Admin\Models\" />
15+
<Folder Include="Areas\Admin\Views\" />
1416
<Folder Include="Areas\Home\Models\" />
1517
<Folder Include="Controllers\" />
1618
</ItemGroup>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace ApiIntegrationMvc.Areas.Admin.Controllers
4+
{
5+
[Area("Admin")]
6+
public class LogsController : Controller
7+
{
8+
public IActionResult Index()
9+
{
10+
return RedirectToAction("Index", "Home", new { area = "Home" });
11+
//return View();
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace ApiIntegrationMvc.Areas.Admin.Controllers
4+
{
5+
[Area("Admin")]
6+
public class RolesController : Controller
7+
{
8+
public IActionResult Index()
9+
{
10+
return RedirectToAction("Index", "Home", new { area = "Home" });
11+
//return View();
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace ApiIntegrationMvc.Areas.Admin.Controllers
4+
{
5+
[Area("Admin")]
6+
public class UsersController : Controller
7+
{
8+
public IActionResult Index()
9+
{
10+
return RedirectToAction("Index", "Home", new { area = "Home" });
11+
//return View();
12+
}
13+
}
14+
}
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ApiIntegrationMvc.Areas.Account.Models;
22
using Microsoft.AspNetCore.Mvc;
3+
using System.Collections.Generic;
34
using System.IdentityModel.Tokens.Jwt;
45
using System.Security.Claims;
56
using System.Text.Json;
@@ -18,33 +19,20 @@ public class HomeController : Controller
1819

1920
public HomeController(IAccessTokenProvider tokens) => _tokens = tokens;
2021

21-
2222
public async Task<IActionResult> Index(CancellationToken ct)
2323
{
24-
var token = await _tokens.GetAccessTokenAsync(ct);
25-
26-
var handler = new JwtSecurityTokenHandler();
27-
var jwt = handler.ReadJwtToken(token);
28-
IEnumerable<Claim> claims = jwt.Claims;
29-
var list = claims.Where(c => c.Type == "categories").Select(c => c.Value).ToList();
30-
if (list.Count == 1)
31-
{
32-
var categories = JsonSerializer.Deserialize<List<Category>>(list[0]);
33-
ViewBag.Categories = categories;
34-
}
35-
else
36-
{
37-
ViewBag.Categories = new List<Category>();
38-
}
3924
return View();
4025
}
4126

27+
4228
public IActionResult Privacy()
4329
{
4430
return View();
4531
}
4632

4733

4834

35+
36+
4937
}
5038
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
@{
22
ViewData["Title"] = "Home Page";
33
}
4-
5-
<div class="text-center">
6-
<h1 class="display-4">Welcome</h1>
7-
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8-
</div>

ApiIntegrationMvc/Areas/Home/Views/Home/_ViewImports.cshtml renamed to ApiIntegrationMvc/Areas/Home/Views/_ViewImports.cshtml

File renamed without changes.

ApiIntegrationMvc/Areas/Home/Views/Home/_ViewStart.cshtml renamed to ApiIntegrationMvc/Areas/Home/Views/_ViewStart.cshtml

File renamed without changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@using UserManagementApi.Contracts.Models
2+
@model IReadOnlyList<Category>
3+
4+
<nav class="app-sidebar">
5+
<!-- Top brand or logo -->
6+
<div class="d-flex align-items-center mb-2">
7+
<i class="bi bi-grid-fill fs-5 me-2"></i>
8+
<span class="fw-bold">IPSys</span>
9+
</div>
10+
<hr />
11+
12+
@for (int i = 0; i < Model.Count; i++)
13+
{
14+
var cat = Model[i];
15+
var collapseId = $"collapse-{cat.Id}";
16+
var expanded = i == 0 ? "true" : "false";
17+
var show = i == 0 ? "show" : "";
18+
19+
<div>
20+
<div class="nav-heading"
21+
data-bs-toggle="collapse"
22+
data-bs-target="#@collapseId"
23+
aria-expanded="@expanded"
24+
aria-controls="@collapseId">
25+
<i class="bi bi-chevron-down me-1"></i>@cat.Name
26+
</div>
27+
<div class="collapse @show" id="@collapseId">
28+
<ul class="nav flex-column mb-2">
29+
@foreach (var m in cat.Modules)
30+
{
31+
<li class="nav-item">
32+
<a class="nav-link"
33+
asp-area="@m.Area"
34+
asp-controller="@m.Controller"
35+
asp-action="@m.Action">
36+
@m.Name
37+
</a>
38+
</li>
39+
}
40+
</ul>
41+
</div>
42+
</div>
43+
44+
@* Divider between groups *@
45+
@if (i < Model.Count - 1)
46+
{
47+
<hr />
48+
}
49+
}
50+
</nav>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Newtonsoft.Json.Linq;
3+
using System.IdentityModel.Tokens.Jwt;
4+
using System.Security.Claims;
5+
using System.Text.Json;
6+
using UserManagement.Sdk.Abstractions;
7+
using UserManagementApi.Contracts.Models;
8+
9+
namespace ApiIntegrationMvc.Views.Shared.Components
10+
{
11+
12+
public sealed class CategoryTreeViewComponent: ViewComponent
13+
{
14+
private readonly IAccessTokenProvider _tokens;
15+
public CategoryTreeViewComponent(IAccessTokenProvider tokens)
16+
=> _tokens = tokens;
17+
18+
public async Task<IViewComponentResult> InvokeAsync()
19+
{
20+
var ct = HttpContext?.RequestAborted ?? default;
21+
var token = await _tokens.GetAccessTokenAsync(ct);
22+
23+
var handler = new JwtSecurityTokenHandler();
24+
var jwt = handler.ReadJwtToken(token);
25+
IEnumerable<Claim> claims = jwt.Claims;
26+
var list = claims.Where(c => c.Type == "categories").Select(c => c.Value).ToList();
27+
IReadOnlyList<Category> categories = new List<Category>();
28+
if (list.Count == 1)
29+
{
30+
categories = JsonSerializer.Deserialize<List<Category>>(list[0]);
31+
}
32+
33+
return View(categories); // Views/Shared/Components/CategoryTree/Default.cshtml
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)