From bd298874c466a1b1a44933c797ba717c4ce5328f Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Fri, 3 Oct 2025 21:27:00 +0200 Subject: [PATCH] Added Locations Delete CRUD element --- src/Controllers/LocationsController.cs | 18 ++++++++++++++++++ src/Services/LdapService.cs | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/Controllers/LocationsController.cs b/src/Controllers/LocationsController.cs index 1d997a6..bdcefc1 100644 --- a/src/Controllers/LocationsController.cs +++ b/src/Controllers/LocationsController.cs @@ -16,4 +16,22 @@ public class LocationsController : Controller return list; } + [HttpGet("Delete")] + public async Task Delete(string cn) + { + if (cn is null) { return false; } + return await Task.Run(() => + { + try + { + _ldap.DeleteLocation(cn); + return true; + } + catch (Exception) + { + return false; + } + }); + } + } diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index 8930cda..c5cb0d7 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -261,6 +261,12 @@ public partial class LdapService : IDisposable DeleteObjectByDn(dn); } + public void DeleteLocation(string cn) + { + string dn = PrependRDN($"cn={cn}", LocationsBaseDn); + DeleteObjectByDn(dn); + } + public async Task UpdateUser(string uid, string attributeName, string attributeValue) { await UpdateObject(UsersBaseDn, "uid", uid, attributeName, attributeValue);