bib_Talk_Chatprogramm/bibtalk/bib-talk/Repository/RegisterDatabase.cs
BlackViron 068ba16156 3 Schichten Model
3 Schichten Model umgesetzt
2024-07-01 16:21:03 +02:00

48 lines
1.6 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
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);
}
}
}
}
}