@page "/database/device" @using Ministreliy.Models @using System.Text.Json @using Newtonsoft.Json @using System.Text @inject IJSRuntime JS @inject NavigationManager NavManager База данных @if (listDT.Count == 0 || listDT == null) {

@msg

} else { @* *@
@foreach (var item in listDT) { }
# Название
@item.Id @item.Name
} @code { //HttpClient http = new(); private DeviceType dt; private List listDT = new(); private string msg = "-= ПОЛУЧАЮ ДАННЫЕ =-", name_type = ""; private int id_type = 1, selected_type = 0; protected override async Task OnInitializedAsync() { HttpClient http = new(); await Task.Delay(1000); http.BaseAddress = new Uri("http://localhost:5262/api/"); var t = await http.GetAsync("Device/GetTypes"); if (t.StatusCode == System.Net.HttpStatusCode.NoContent) { msg = "-= ДАННЫХ НЕТ =-"; } else { listDT = JsonConvert.DeserializeObject>(await t.Content.ReadAsStringAsync()); //id_type = listDT.Count + 1; var a = listDT.Select(listDT => listDT.Id).ToList(); id_type = Enumerable.Range(1, int.MaxValue).FirstOrDefault(i => !a.Contains(i)); } } private async Task SaveType() { HttpClient http = new(); dt = new(); dt.Id = id_type; dt.Name = name_type; http.BaseAddress = new Uri("http://localhost:5262/api/"); using StringContent content = new StringContent( JsonConvert.SerializeObject(dt), Encoding.UTF8, "application/json" ); var r = await http.PostAsync("Device/AddType", content); if (r.IsSuccessStatusCode) { await JS.InvokeVoidAsync("eval", $"var myModal = bootstrap.Modal.getInstance(document.querySelector('.modal1')); myModal.hide();"); await Task.Delay(150); id_type = listDT.Count+1; NavManager.NavigateTo(NavManager.Uri, forceLoad: true); } } private async Task DelType() { HttpClient http = new(); http.BaseAddress = new Uri("http://localhost:5262/api/"); var r = await http.DeleteAsync($"Device/DelType?id={selected_type}"); if (r.IsSuccessStatusCode) { await JS.InvokeVoidAsync("eval", $"var myModal = bootstrap.Modal.getInstance(document.querySelector('.modal2')); myModal.hide();"); await Task.Delay(250); id_type = listDT.Count + 1; NavManager.NavigateTo(NavManager.Uri, forceLoad: true); } } }