@using System.Collections.ObjectModel @inject NavigationManager NavigationManager @inject ServerHttpPathService ServerHttpPathService @inject IMessageService MessageService @inject ILogger Logger @if (context != null && context.Id != Guid.Empty) { }
@code { [Parameter] public Guid ServerId { get; set; } [Parameter] public string WorkingDirectory { get; set; } ObservableCollection _httpPaths = new(); protected override async Task OnInitializedAsync() => await LoadHttpPaths(); async Task LoadHttpPaths() { _httpPaths = new ObservableCollection(await ServerHttpPathService.GetAsync(p => p.ServerId == ServerId)); } void Add() { _httpPaths.Add(new ServerHttpPath { ServerId = ServerId, }); } async Task Remove(ServerHttpPath httpPath) { if (httpPath.Id != Guid.Empty) await ServerHttpPathService.DeleteAsync(httpPath); _httpPaths.Remove(httpPath); } public async Task Save() { try { foreach (var httpPath in _httpPaths) { if (httpPath.Id == Guid.Empty) await ServerHttpPathService.AddAsync(httpPath); else await ServerHttpPathService.UpdateAsync(httpPath); } await LoadHttpPaths(); MessageService.Success("HTTP paths updated!"); } catch (Exception ex) { MessageService.Error("Could not update HTTP paths!"); Logger.LogError(ex, "Could not update HTTP paths!"); } } }