1
0

95 lines
2.2 KiB
Plaintext
Executable File

@namespace ServerManagement.Components.Controls
@inject NavigationManager NavigationManager
@if (Server != null)
{
<tr @key="Server.Id" style="background-color: @GetBackgroundColor();">
<td>
@Server.Name
</td>
<td>
@Server.City
</td>
<td>
<span style="color:@(Server.IsOnline ? "green" : "red")">
@(Server.IsOnline ? "online" : "offline")
</span>
</td>
<td>
@if (Server.IsOnline)
{
Random random = new Random();
int randomNumber = random.Next(0, 500);
<text>@randomNumber users online</text>
}
else
{
<text>N/A</text>
}
</td>
<td>
@if (Server.IsOnline)
{
<button type="button" class="btn btn-outline-danger"
@onclick="@(() => { Server.IsOnline = false; })">
Turn off
</button>
}
else
{
<button type="button" class="btn btn-outline-success"
@onclick="@(() => { Server.IsOnline = true; })">
Turn on
</button>
}
&nbsp;
<a href="@($"/server/{Server.Id}")" class="btn btn-primary">Edit</a>
</td>
<td>
<EditForm
Model="Server"
FormName="@($"formDeleteServer{Server.Id}")"
OnValidSubmit="@(() => { DeleteServer(Server.Id); })">
<button type="submit" class="btn btn-danger">Delete</button>
</EditForm>
</td>
</tr>
}
@code {
[Parameter]
public Server? Server { get; set; }
[CascadingParameter(Name="SelectedCity")]
public string? SelectedCity { get; set; }
private void DeleteServer(int serverId)
{
if (serverId > 0)
{
ServersRepository.DeleteServer(serverId);
NavigationManager.Refresh(forceReload: true);
}
}
private string GetBackgroundColor()
{
if (SelectedCity != null) {
switch (this.SelectedCity)
{
case "Eindhoven": return "lightskyblue";
case "Helmond": return "lightcoral";
case "Oosterhout": return "lightgreen";
case "Roosendaal": return "lightsalmon";
case "Deurne": return "lightpink";
default:
return "white";
}
}
else
{
return "white";
}
}
}