@page "/admin/servers/all/update/{Id:int}"
@using MoonCore.Blazor.FlyonUi.Components
@using MoonCore.Blazor.FlyonUi.Toasts
@using MoonCore.Helpers
@using Moonlight.Shared.Http.Responses.Admin.Users
@using MoonlightServers.Shared.Http.Requests.Admin.Servers
@using MoonlightServers.Shared.Http.Responses.Admin.Servers
@using MoonlightServers.Frontend.UI.Components.Servers.UpdatePartials
@using MoonlightServers.Shared.Http.Responses.Admin.NodeAllocations
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
@inject ToastService ToastService
@attribute [Authorize(Policy = "permissions:admin.servers.update")]
Back
Update
@code
{
[Parameter] public int Id { get; set; }
private HandleForm Form;
private UpdateServerRequest Request;
private ServerResponse Server;
public List Allocations = new();
public UserResponse Owner;
private async Task LoadAsync(LazyLoader _)
{
Server = await ApiClient.GetJson($"api/admin/servers/{Id}");
Request = new()
{
Name = Server.Name,
AllocationIds = Server.AllocationIds,
OwnerId = Server.OwnerId,
Cpu = Server.Cpu,
Disk = Server.Disk,
DockerImageIndex = Server.DockerImageIndex,
Memory = Server.Memory,
StartupOverride = Server.StartupOverride
};
foreach (var allocationId in Server.AllocationIds)
{
var allocation = await ApiClient.GetJson(
$"api/admin/servers/nodes/{Server.NodeId}/allocations/{allocationId}"
);
Allocations.Add(allocation);
}
Owner = await ApiClient.GetJson(
$"api/admin/users/{Server.OwnerId}"
);
}
private async Task OnSubmit()
{
Request.AllocationIds = Allocations.Select(x => x.Id).ToArray();
Request.OwnerId = Owner.Id;
await ApiClient.Patch($"api/admin/servers/{Id}", Request);
await ToastService.SuccessAsync("Successfully updated server");
Navigation.NavigateTo("/admin/servers/all");
}
}