bib_Talk_Chatprogramm/bibtalk/bib-talk/Business/RegisterManager.cs

50 lines
1.4 KiB
C#
Raw Normal View History

using bib_talk.Repository;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using System.Windows;
namespace bib_talk.Business
{
public class RegisterManager
{
private RegisterDatabase registerDatabase; // RegisterDatabase Objekt initialisieren
// Konstruktor für den RegisterManager
public RegisterManager(RegisterWindow registerWindow)
{
registerDatabase = new RegisterDatabase(registerWindow); // RegisterDatabase Objekt deklarieren
}
// Methode um einen neuen Nutzer zu Registrieren via der RegisterDatabase
public async void RegisterServer()
{
await registerDatabase.RegisterServer();
}
// DEBUG METHODE
// Methode um einen Bot Nutzer auf der Datenbank anzulegen
public async void RegisterBots(string username, string password, string email, string birthday)
{
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);
}
}
}
}
}