From 7eff665f81ca11d975c1efe2d0e75c629d880b1e Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Fri, 3 Oct 2025 21:39:56 +0200 Subject: [PATCH] Added Assets Delete CRUD element --- src/Controllers/AssetsController.cs | 19 ++++++++++++++++++- src/Services/LdapService.cs | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Controllers/AssetsController.cs b/src/Controllers/AssetsController.cs index bdf0acf..4c4a048 100644 --- a/src/Controllers/AssetsController.cs +++ b/src/Controllers/AssetsController.cs @@ -15,11 +15,28 @@ public class AssetsController : Controller _ldap = ldap ?? throw new ArgumentNullException(nameof(ldap)); } - // GET: /Assets [HttpGet("Index")] public async Task>> Index() { var list = await _ldap.ListDeviceAsync(); return list; } + + [HttpGet("Delete")] + public async Task Delete(string cn) + { + if (cn is null) { return false; } + return await Task.Run(() => + { + try + { + _ldap.DeleteAsset(cn); + return true; + } + catch (Exception) + { + return false; + } + }); + } } \ No newline at end of file diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index b267708..323e4cc 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -269,6 +269,12 @@ public partial class LdapService : IDisposable DeleteObjectByDn(dn); } + public void DeleteAsset(string cn) + { + string dn = PrependRDN($"cn={cn}", AssetsBaseDn); + DeleteObjectByDn(dn); + } + public async Task UpdateUser(string uid, string attributeName, string attributeValue) { await UpdateObject(UsersBaseDn, "uid", uid, attributeName, attributeValue);