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; public RegisterDatabase(RegisterWindow registerWindow) { this.registerWindow = registerWindow; } 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); } } } } }