From 45a94c99fc288dfe86c3d7a25b600212a5de21ed Mon Sep 17 00:00:00 2001 From: Mohd Ariff Date: Thu, 12 Dec 2024 14:30:49 +0800 Subject: [PATCH] Update --- Controllers/API/AdminAPI.cs | 4 ++-- Views/Admin/UserAdmin.cshtml | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Controllers/API/AdminAPI.cs b/Controllers/API/AdminAPI.cs index 91fe2f1..a3668c0 100644 --- a/Controllers/API/AdminAPI.cs +++ b/Controllers/API/AdminAPI.cs @@ -101,7 +101,7 @@ namespace PSTW_CentralSystem.Controllers.API { // Fetch all users excluding those with roles SuperAdmin or SystemAdmin var allUsers = await _authDbContext.Users - .Include(u => u.Department) + .Include(u => u.Department).ThenInclude(d => d!.Company) .ToListAsync(); foreach (var u in allUsers) @@ -115,7 +115,7 @@ namespace PSTW_CentralSystem.Controllers.API } else { - userInfo = await _authDbContext.Users.Include(u => u.Department).ToListAsync(); + userInfo = await _authDbContext.Users.Include(u => u.Department).ThenInclude(d => d!.Company).ToListAsync(); } return Ok(new { UserInfo = userInfo }); diff --git a/Views/Admin/UserAdmin.cshtml b/Views/Admin/UserAdmin.cshtml index c8b8d97..05e7c77 100644 --- a/Views/Admin/UserAdmin.cshtml +++ b/Views/Admin/UserAdmin.cshtml @@ -72,9 +72,7 @@ }) .then(response => response.json()) .then(data => { - if (data.length > 0) { - this.userList = data.length ? data : []; - } + this.userList = data.userInfo.length ? data.userInfo : []; this.initiateTable(); }) .catch(error => { @@ -121,8 +119,9 @@ }, initiateTable() { self = this; + console.log(self.userList) this.itemDatatable = $('#userDatatable').DataTable({ - "data": this.userList, + "data": self.userList, "columns": [ { "title": "UID",