diff --git a/src/Controllers/AssetsController.cs b/src/Controllers/AssetsController.cs index 1b803e5..f65f9ea 100644 --- a/src/Controllers/AssetsController.cs +++ b/src/Controllers/AssetsController.cs @@ -66,6 +66,7 @@ public class AssetsController : Controller [HttpPost("Create")] public async Task Create([FromBody]AssetsCreateRequestModel assetModel) { + string? assetId; AssetsCreateResponseModel result; if (assetModel is null) { @@ -82,8 +83,8 @@ public class AssetsController : Controller [ new LdapAttribute("objectClass", ["top", "device", "extensibleObject"]), ]; - - attributeSet.Add(new LdapAttribute("cn", await _ldap.GetAssetCounterAndIncrementAsync())); + assetId = await _ldap.GetAssetCounterAndIncrementAsync(); + attributeSet.Add(new LdapAttribute("cn", assetId)); if (assetModel.SerialNumber != null) { attributeSet.Add(new LdapAttribute("serialNumber", assetModel.SerialNumber)); @@ -107,7 +108,7 @@ public class AssetsController : Controller } await _ldap.CreateAsset(attributeSet); - result = new AssetsCreateResponseModel(successful: true); + result = new AssetsCreateResponseModel(successful: true, assetId); } catch (Exception e) { diff --git a/src/Models/AssetsResponseModel.cs b/src/Models/AssetsResponseModel.cs index d2577f2..8257285 100644 --- a/src/Models/AssetsResponseModel.cs +++ b/src/Models/AssetsResponseModel.cs @@ -1,8 +1,9 @@ using Berufsschule_HAM.Models; -public class AssetsCreateResponseModel(bool successful, string exception = "None") +public class AssetsCreateResponseModel(bool successful, string? assetId = null, string exception = "None") { public bool Success { get; set; } = successful; + public string? AssetId { get; set; } = assetId; public string? Exception { get; set; } = exception; } diff --git a/src/Views/Home/Assets.cshtml b/src/Views/Home/Assets.cshtml index b54376d..ec34ca8 100644 --- a/src/Views/Home/Assets.cshtml +++ b/src/Views/Home/Assets.cshtml @@ -333,6 +333,39 @@ bootstrap.Modal.getInstance(createModalEl).hide(); createForm.reset(); attributesContainer.innerHTML = ''; + const tableBody = document.querySelector('table tbody'); + if (tableBody) { + const newRow = document.createElement('tr'); + newRow.innerHTML = ` + ${jsonData.Owner || ''} + ${result.assetId || ''} + ${jsonData.Name || ''} + ${jsonData.Location || ''} + +
+ + +
+ + `; + + newRow.classList.add('table-success'); + setTimeout(() => { + newRow.classList.toggle('table-success'); + }, 500); + tableBody.append(newRow); + } showToast('@T["Asset created successfully"]', 'success'); } else { showToast(`${result.reason || '@T["Error creating asset"]'}`, 'danger');