Skip to content

Commit

Permalink
[Upgrade]: Add location nav use
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot-SomeOne committed Oct 23, 2024
1 parent aea5e1e commit f7001ea
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Data/InitDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ IServiceProvider serviceProvider
context.NavBarPages.AddRange(
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyGiaoVien",
Action = "Index",
Expand All @@ -137,6 +138,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLySinhVien",
Action = "Index",
Expand All @@ -145,6 +147,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyLopHocPhan",
Action = "Index",
Expand All @@ -153,6 +156,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyMonHoc",
Action = "Index",
Expand All @@ -161,6 +165,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyKhoa",
Action = "Index",
Expand All @@ -169,6 +174,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyNganh",
Action = "Index",
Expand All @@ -177,6 +183,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyNguyenVong",
Action = "HocNangDiem",
Expand All @@ -185,6 +192,7 @@ IServiceProvider serviceProvider
},
new ViewNavItem
{
LocationNavItem = "ADMIN",
Area = "ADMIN",
Controller = "QuanLyNguyenVong",
Action = "HocNangLai",
Expand Down
61 changes: 61 additions & 0 deletions Migrations/ViewDb/20241023090215_addLocationNav.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Migrations/ViewDb/20241023090215_addLocationNav.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace web_qlsv.Migrations.ViewDb
{
/// <inheritdoc />
public partial class addLocationNav : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "LocationNavItem",
table: "NavBarPages",
type: "nvarchar(max)",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LocationNavItem",
table: "NavBarPages");
}
}
}
3 changes: 3 additions & 0 deletions Migrations/ViewDb/ViewDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("IconClass")
.HasColumnType("nvarchar(max)");
b.Property<string>("LocationNavItem")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("NavBarPages");
Expand Down
1 change: 1 addition & 0 deletions Models/Views/ViewNavItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace qlsv.Models;

public class ViewNavItem {
public string? Id { get; set; }
public string? LocationNavItem { get; set; }
public string? Area { get; set; }
public string? Controller { get; set; }
public string? Action { get; set; }
Expand Down
12 changes: 9 additions & 3 deletions ViewComponents/NavbarListViewComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ public async Task<IViewComponentResult> InvokeAsync(string page, params object[]
if (page.ToUpper() == "ADMIN")
{
var listNavbar = await _dbContext.NavBarPages
.Where(p => p.Area == "ADMIN")
.Where(p => p.LocationNavItem.ToUpper() == "ADMIN")
.ToListAsync();
return View("AdminPage", listNavbar);
}
if (page.ToUpper() == "STUDENT")
{
return View("StudentPage");
var listNavbar = await _dbContext.NavBarPages
.Where(p => p.LocationNavItem.ToUpper() == "STUDENT")
.ToListAsync();
return View("StudentPage", listNavbar);
}
if (page.ToUpper() == "TEACHER")
{
return View("TeacherPage");
var listNavbar = await _dbContext.NavBarPages
.Where(p => p.LocationNavItem.ToUpper() == "TEACHER")
.ToListAsync();
return View("TeacherPage", listNavbar);
}
return View("Default");
}
Expand Down
6 changes: 5 additions & 1 deletion Views/Shared/Components/NavbarList/AdminPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
@foreach (var navbar in Model)
{
<li class="nav-item">
<a class="nav-link" asp-area="@navbar.Area">
<a class="nav-link"
asp-area="@navbar.Area"
asp-controller="@navbar.Controller"
asp-action="@navbar.Action"
>
<i class="@navbar.IconClass"></i>
<span>@navbar.Content</span></a>
</li>
Expand Down

0 comments on commit f7001ea

Please sign in to comment.