diff --git a/src/Controllers/AssetsController.cs b/src/Controllers/AssetsController.cs index feefbaf..d961049 100644 --- a/src/Controllers/AssetsController.cs +++ b/src/Controllers/AssetsController.cs @@ -19,7 +19,7 @@ public class AssetsController : Controller } [HttpGet("Index")] - public async Task>> Index() + public async Task> Index() { var list = await _ldap.ListDeviceAsync(); return list; diff --git a/src/Controllers/HomeController.cs b/src/Controllers/HomeController.cs index b4217e0..52e9ec2 100644 --- a/src/Controllers/HomeController.cs +++ b/src/Controllers/HomeController.cs @@ -22,9 +22,23 @@ public class HomeController : Controller [Authorize] [HttpGet("Index")] [HttpGet("/")] - public IActionResult Index() + public async Task Index() { - return View(); + IEnumerable users = await _ldap.ListUsersAsync(); + IEnumerable assets = await _ldap.ListDeviceAsync(); + IEnumerable locations = await _ldap.ListLocationsAsync(); + List assetsTableViewModels = []; + foreach (AssetModel asset in assets) + { + assetsTableViewModels.Add(new() + { + AssetCn = asset.Cn, + AssetName = asset.Name, + LocationName = asset.Location, + UserUID = asset.Owner?.Split('=')[1], + }); + } + return View(new HomeIndexViewModel() { AssetsTableViewModels = assetsTableViewModels }); } [HttpPost("Login")] diff --git a/src/Controllers/LocationsController.cs b/src/Controllers/LocationsController.cs index 912bc2a..1833342 100644 --- a/src/Controllers/LocationsController.cs +++ b/src/Controllers/LocationsController.cs @@ -18,9 +18,9 @@ public class LocationsController : Controller } [HttpGet("Index")] - public async Task>> Index() + public async Task> Index() { - IEnumerable> list = await _ldap.ListLocationsAsync(); + IEnumerable list = await _ldap.ListLocationsAsync(); return list; } diff --git a/src/Models/AssetsModel.cs b/src/Models/AssetsModel.cs index 665e0f6..ed0832b 100644 --- a/src/Models/AssetsModel.cs +++ b/src/Models/AssetsModel.cs @@ -43,4 +43,12 @@ public class AssetPurchase public string? PurchaseValue { get; set; } public string? PurchasedAt { get; set; } public string? PurchasedBy { get; set; } +} + +public class AssetsTableViewModel +{ + public string? UserUID { get; set; } + public required string AssetCn { get; set; } + public string? AssetName { get; set; } + public string? LocationName { get; set; } } \ No newline at end of file diff --git a/src/Models/HomeViewModels.cs b/src/Models/HomeViewModels.cs new file mode 100644 index 0000000..aaf971e --- /dev/null +++ b/src/Models/HomeViewModels.cs @@ -0,0 +1,6 @@ +namespace Berufsschule_HAM.Models; + +public class HomeIndexViewModel +{ + public required IEnumerable AssetsTableViewModels { get; set; } +} \ No newline at end of file diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index ffcc3ed..1e6c101 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -49,14 +49,20 @@ public partial class LdapService : IDisposable public string[] AssetsAttributes => ["CN", "description", "l", "owner", "serialNumber", "name"]; public string[] LocationsAttributes => ["cn", "l", "street", "description"]; public string[] GroupsAttributes => ["cn", "gidNumber", "description"]; - public async Task>> ListLocationsAsync() + public async Task> ListLocationsAsync() { - return await ListObjectBy(LocationsBaseDn, "", LocationsAttributes); + IEnumerable> locations = await ListObjectBy(LocationsBaseDn, "", LocationsAttributes); + List models = []; + locations.ToList().ForEach(x => models.Add(new LocationModel(x) {Cn = x["cn"]})); + return models; } - public async Task>> ListUsersAsync() + public async Task> ListUsersAsync() { - return await ListObjectBy(UsersBaseDn, "", UsersAttributes); + IEnumerable> users = await ListObjectBy(UsersBaseDn, "", UsersAttributes); + List models = []; + users.ToList().ForEach(x => models.Add(new UserModel(x) {Uid = x["uid"]})); + return models; } public async Task GetMigrationVersionAsync() @@ -158,9 +164,12 @@ public partial class LdapService : IDisposable return new AssetModel((await ListObjectBy(AssetsBaseDn, $"cn={cn}", attributes)).First()) { Cn = cn }; } - public async Task>> ListDeviceAsync() + public async Task> ListDeviceAsync() { - return await ListObjectBy(AssetsBaseDn, "(objectClass=device)", AssetsAttributes); + IEnumerable> devices = await ListObjectBy(AssetsBaseDn, "(objectClass=device)", AssetsAttributes); + List models = []; + devices.ToList().ForEach(x => models.Add(new AssetModel(x) {Cn = x["cn"]})); + return models; } public async Task CreateUser(string uid, LdapAttributeSet attributeSet) diff --git a/src/Views/Home/Index.cshtml b/src/Views/Home/Index.cshtml index 06924ab..710229d 100644 --- a/src/Views/Home/Index.cshtml +++ b/src/Views/Home/Index.cshtml @@ -1,4 +1,6 @@ @using Microsoft.AspNetCore.Mvc.Localization +@using Berufsschule_HAM.Models +@model HomeIndexViewModel @inject IViewLocalizer T @{ ViewData["Title"] = T["Home Page"]; @@ -32,50 +34,19 @@ + @{ + foreach (AssetsTableViewModel assetsTableViewModel in Model.AssetsTableViewModels) + { - John Doe - 4827391 - Lorem Ipsum dolor sit amet - BTG Raum 317 + @assetsTableViewModel.UserUID + @assetsTableViewModel.AssetCn + @assetsTableViewModel.AssetName + @assetsTableViewModel.LocationName
-
- - - - Max Mustermann - 9150732 - Lorem Ipsum dolor sit amet - BTG Raum 317 - -
- - -
- - - - Otto Normalverbraucher - 1642235 - Lorem Ipsum dolor sit amet - BTG Raum 317 - -
- -
+ } + }