Fixed server creation allocation loading

This commit is contained in:
Marcel Baumgartner
2024-05-30 18:27:36 +02:00
parent 96a906b717
commit b5119b6be1

View File

@@ -68,14 +68,23 @@
.Include(x => x.Node); .Include(x => x.Node);
} }
private IEnumerable<ServerAllocation> LoadFreeAllocations(Repository<ServerAllocation> repository, Server currentServer) private IEnumerable<ServerAllocation> LoadFreeAllocations(Repository<ServerAllocation> repository, Server? currentServer)
{ {
return currentServer.Allocations.Concat( if (currentServer == null)
repository {
return repository
.Get() .Get()
.FromSqlRaw($"SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL AND ServerNodeId = {currentServer.Node.Id}") .FromSqlRaw("SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL");
.AsEnumerable() // => executes the sql }
); else
{
return currentServer.Allocations.Concat(
repository
.Get()
.FromSqlRaw($"SELECT * FROM `ServerAllocations` WHERE ServerId IS NULL AND ServerNodeId = {currentServer.Node.Id}")
.AsEnumerable() // => executes the sql
);
}
} }
private async Task CustomAdd(Server form) => await ServerService.Create(form); private async Task CustomAdd(Server form) => await ServerService.Create(form);