Merge pull request #55 from LD-Reborn/15-feature-crud---assets-delete

Added Assets Delete CRUD element
This commit is contained in:
LD50
2025-10-03 21:40:18 +02:00
committed by GitHub
2 changed files with 24 additions and 1 deletions

View File

@@ -15,11 +15,28 @@ public class AssetsController : Controller
_ldap = ldap ?? throw new ArgumentNullException(nameof(ldap));
}
// GET: /Assets
[HttpGet("Index")]
public async Task<IEnumerable<Dictionary<string, string>>> Index()
{
var list = await _ldap.ListDeviceAsync();
return list;
}
[HttpGet("Delete")]
public async Task<bool> Delete(string cn)
{
if (cn is null) { return false; }
return await Task.Run(() =>
{
try
{
_ldap.DeleteAsset(cn);
return true;
}
catch (Exception)
{
return false;
}
});
}
}

View File

@@ -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);