using Newtonsoft.Json; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Windows; namespace bib_talk.Repository { public class RegisterDatabase { RegisterWindow registerWindow; // RegisterWindow initailisieren // Konstruktor für die RegisterDatabase public RegisterDatabase(RegisterWindow registerWindow) { this.registerWindow = registerWindow; } // Methode um einen Nutzer zu registrieren und die Daten // in die Datenbank zu schreiben public async Task RegisterServer() { string username = registerWindow.usernbox.Text; string password = registerWindow.passwordbox.Password; string email = registerWindow.emailbox.Text; string birthday = $"{registerWindow.bday1.Text}.{registerWindow.bday2.Text}.{registerWindow.bday3.Text}"; var newUser = new { Username = username, Password = password, Email = email, Birthday = birthday, IsOnline = "" }; string json = JsonConvert.SerializeObject(newUser); using (var client = new HttpClient()) { var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync("http://daddypig.dns.navy:5114/api/users/register", content); if (response.IsSuccessStatusCode) { MessageBox.Show("Registrierung erfolgreich."); } else { MessageBox.Show("Registrierung fehlgeschlagen. " + response); } } } } }