3 Schichten Model
3 Schichten Model umgesetzt
This commit is contained in:
47
bibtalk/bib-talk/Repository/RegisterDatabase.cs
Normal file
47
bibtalk/bib-talk/Repository/RegisterDatabase.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user