mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Add return model to AssetsController
This commit is contained in:
@@ -106,20 +106,28 @@ public class AssetsController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Delete")]
|
[HttpGet("Delete")]
|
||||||
public async Task<bool> Delete(string cn)
|
public async Task<AssetsDeleteResponseModel> Delete(string cn)
|
||||||
{
|
{
|
||||||
if (cn is null) { return false; }
|
AssetsDeleteResponseModel response;
|
||||||
return await Task.Run(() =>
|
return await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
if (cn is null)
|
||||||
|
{
|
||||||
|
response = new AssetsDeleteResponseModel(false, AssetsDeleteErrorEnum.CnIsNull);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ldap.DeleteAsset(cn);
|
await _ldap.DeleteAssetAsync(cn);
|
||||||
return true;
|
response = new AssetsDeleteResponseModel(true, AssetsDeleteErrorEnum.None);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return false;
|
response = new AssetsDeleteResponseModel(false, AssetsDeleteErrorEnum.UnableToDeleteAsset, e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ public class GroupsController : Controller
|
|||||||
[HttpGet("Delete")]
|
[HttpGet("Delete")]
|
||||||
public async Task<bool> Delete(string uid)
|
public async Task<bool> Delete(string uid)
|
||||||
{
|
{
|
||||||
return await Task.Run(() =>
|
return await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ldap.DeleteGroup(uid);
|
await _ldap.DeleteGroupAsync(uid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ public class LocationsController : Controller
|
|||||||
public async Task<bool> Delete(string cn)
|
public async Task<bool> Delete(string cn)
|
||||||
{
|
{
|
||||||
if (cn is null) { return false; }
|
if (cn is null) { return false; }
|
||||||
return await Task.Run(() =>
|
return await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ldap.DeleteLocation(cn);
|
await _ldap.DeleteLocationAsync(cn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ public class UsersController : Controller
|
|||||||
[HttpGet("Delete")]
|
[HttpGet("Delete")]
|
||||||
public async Task<bool> Delete(string uid)
|
public async Task<bool> Delete(string uid)
|
||||||
{
|
{
|
||||||
return await Task.Run(() =>
|
return await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_ldap.DeleteUser(uid);
|
await _ldap.DeleteUserAsync(uid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|||||||
14
src/Models/AssetsDeleteResponseModel.cs
Normal file
14
src/Models/AssetsDeleteResponseModel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
public class AssetsDeleteResponseModel(bool successful, AssetsDeleteErrorEnum errorReason, string exception = "none")
|
||||||
|
{
|
||||||
|
public bool Success { get; set; } = successful;
|
||||||
|
public AssetsDeleteErrorEnum Reason { get; set; } = errorReason;
|
||||||
|
|
||||||
|
public string? Exception { get; set; } = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AssetsDeleteErrorEnum
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CnIsNull,
|
||||||
|
UnableToDeleteAsset
|
||||||
|
}
|
||||||
@@ -275,28 +275,28 @@ public async Task CreateAsset(LdapAttributeSet attributeSet)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteUser(string uid)
|
public async Task DeleteUserAsync(string uid)
|
||||||
{
|
{
|
||||||
string dn = PrependRDN($"uid={uid}", UsersBaseDn);
|
string dn = PrependRDN($"uid={uid}", UsersBaseDn);
|
||||||
DeleteObjectByDn(dn);
|
await DeleteObjectByDnAsync(dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteGroup(string cn)
|
public async Task DeleteGroupAsync(string cn)
|
||||||
{
|
{
|
||||||
string dn = PrependRDN($"cn={cn}", GroupsBaseDn);
|
string dn = PrependRDN($"cn={cn}", GroupsBaseDn);
|
||||||
DeleteObjectByDn(dn);
|
await DeleteObjectByDnAsync(dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteLocation(string cn)
|
public async Task DeleteLocationAsync(string cn)
|
||||||
{
|
{
|
||||||
string dn = PrependRDN($"cn={cn}", LocationsBaseDn);
|
string dn = PrependRDN($"cn={cn}", LocationsBaseDn);
|
||||||
DeleteObjectByDn(dn);
|
await DeleteObjectByDnAsync(dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteAsset(string cn)
|
public async Task DeleteAssetAsync(string cn)
|
||||||
{
|
{
|
||||||
string dn = PrependRDN($"cn={cn}", AssetsBaseDn);
|
string dn = PrependRDN($"cn={cn}", AssetsBaseDn);
|
||||||
DeleteObjectByDn(dn);
|
await DeleteObjectByDnAsync(dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateUser(string uid, string attributeName, string attributeValue)
|
public async Task UpdateUser(string uid, string attributeName, string attributeValue)
|
||||||
@@ -337,7 +337,7 @@ public async Task CreateAsset(LdapAttributeSet attributeSet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void DeleteObjectByDn(string dn)
|
public async Task DeleteObjectByDnAsync(string dn)
|
||||||
{
|
{
|
||||||
await _conn.DeleteAsync(dn);
|
await _conn.DeleteAsync(dn);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user