Implemented /Home/Location table and delete action

This commit is contained in:
2025-10-10 09:35:53 +02:00
parent 432a28271b
commit 1e13ea11d7
6 changed files with 67 additions and 37 deletions

View File

@@ -54,9 +54,21 @@ public class HomeController : Controller
}
[HttpGet("Locations")]
public ActionResult Locations()
public async Task<ActionResult> LocationsAsync()
{
return View();
IEnumerable<LocationModel> locations = await _ldap.ListLocationsAsync();
List<LocationTableViewModel> LocationsTableViewModels = [];
foreach (LocationModel location in locations)
{
LocationsTableViewModels.Add(new()
{
LocationID = location.Location,
LocationName = location.Description?.Location ?? "",
RoomNumber = location.Description?.RoomNumber ?? "",
Seat = location.Description?.Seat ?? ""
});
}
return View(new LocationsIndexViewModel() { LocationTableViewModels = LocationsTableViewModels });
}
[HttpGet("Users")]

View File

@@ -40,7 +40,7 @@ public class LocationsController : Controller
new LdapAttribute("l", location),
new LdapAttribute("description", JsonSerializer.Serialize(room))
];
await _ldap.CreateLocation(attributeSet);
return true;
}
@@ -52,22 +52,20 @@ public class LocationsController : Controller
}
[HttpGet("Delete")]
public async Task<bool> Delete(string cn)
public async Task<LocationsDeleteRequestModel> DeleteAsync(string cn)
{
if (cn is null) { return false; }
return await Task.Run(async () =>
if (cn is null) { return new(false); }
try
{
try
{
await _ldap.DeleteLocationAsync(cn);
return true;
}
catch (Exception)
{
return false;
}
});
await _ldap.DeleteLocationAsync(cn);
return new(true);
}
catch (Exception ex)
{
return new(false, ex.Message);
}
}
[HttpPost("Update")]
public async Task<bool> Update(LocationsModifyRequestModel requestModel)
{