@using Moonlight.App.Database.Entities @using Moonlight.App.Repositories @using Microsoft.EntityFrameworkCore @using Moonlight.App.Services @using Moonlight.App.Services.Interop @using BlazorTable @inject Repository ServerRepository @inject Repository NodeAllocationRepository @inject AlertService AlertService @inject SmartTranslateService SmartTranslateService
@foreach (var allocation in Server.Allocations) { }
@(Server.Node.Fqdn + ":" + allocation.Port)
@code { [CascadingParameter] public Server Server { get; set; } private async Task AddAllocation() { // We have sadly no choice to use entity framework to do what the sql call does, there // are only slower ways, so we will use a raw sql call as a exception var freeAllocation = NodeAllocationRepository .Get() .FromSqlRaw($"SELECT * FROM `NodeAllocations` WHERE ServerId IS NULL AND NodeId={Server.Node.Id} LIMIT 1") .FirstOrDefault(); if (freeAllocation == null) { await AlertService.Error( SmartTranslateService.Translate("No free allocation found")); return; } Server.Allocations.Add(freeAllocation); ServerRepository.Update(Server); await InvokeAsync(StateHasChanged); } private async Task DeleteAllocation(NodeAllocation nodeAllocation) { Server.Allocations.Remove(nodeAllocation); ServerRepository.Update(Server); await InvokeAsync(StateHasChanged); } }