CharakterListe.xaml.cs gelöscht
This commit is contained in:
parent
5dfc357c05
commit
047c38872d
@ -1,49 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Pen_Paper_Main
|
||||
{
|
||||
public partial class CharakterListe : Window
|
||||
{
|
||||
public CharakterListe() { InitializeComponent(); }
|
||||
private class CharVm { public string name{get;set;}=""; public string username{get;set;}=""; }
|
||||
|
||||
private async void Window_Loaded(object s,RoutedEventArgs e) => await LoadAsync();
|
||||
|
||||
private async Task LoadAsync() {
|
||||
using var http=new HttpClient();
|
||||
var json=await http.GetStringAsync("http://localhost/api/characters.php?action=list");
|
||||
using var doc=JsonDocument.Parse(json);
|
||||
var items=new List<CharVm>();
|
||||
foreach(var el in doc.RootElement.GetProperty("items").EnumerateArray()) {
|
||||
items.Add(new CharVm {
|
||||
name=el.GetProperty("name").GetString()??"",
|
||||
username=el.GetProperty("username").GetString()??""
|
||||
});
|
||||
}
|
||||
LstChars.ItemsSource=items;
|
||||
}
|
||||
|
||||
private void Close_Click(object s,RoutedEventArgs e)=>Close();
|
||||
|
||||
private async void New_Click(object s,RoutedEventArgs e) {
|
||||
var dlg=new CharakterNeu(); dlg.Owner=this; dlg.ShowDialog();
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async void Delete_Click(object s,RoutedEventArgs e) {
|
||||
if(LstChars.SelectedItem is CharVm vm) {
|
||||
using var http=new HttpClient();
|
||||
var url=$"http://localhost/api/characters.php?action=delete&username={vm.username}&name={vm.name}";
|
||||
var resp=await http.DeleteAsync(url);
|
||||
var body=await resp.Content.ReadAsStringAsync();
|
||||
MessageBox.Show(body);
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user