From f9d5053029f0837877fe1fe63312fb6b915e30b6 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 28 Aug 2024 13:53:39 +0200 Subject: [PATCH] Code fertig Kommentiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kommentare hinzugefügt wo sie noch gefehlt haben --- bibtalk/bib-talk/Business/LoginManager.cs | 48 +++++++++--------- .../bib-talk/Business/MainWindowManager.cs | 17 ++++--- bibtalk/bib-talk/Business/Message.cs | 1 + bibtalk/bib-talk/Business/MessageDto.cs | 1 + bibtalk/bib-talk/Business/RegisterManager.cs | 9 +++- bibtalk/bib-talk/Business/User.cs | 3 ++ bibtalk/bib-talk/Repository/LoginDatabase.cs | 6 ++- .../bib-talk/Repository/MainWindowDatabase.cs | 21 ++++---- .../bib-talk/Repository/RegisterDatabase.cs | 5 +- bibtalk/bib-talk/UI/Login.xaml | 6 +-- bibtalk/bib-talk/UI/Login.xaml.cs | 49 ++++++++++--------- bibtalk/bib-talk/UI/MainWindow.xaml | 8 +-- bibtalk/bib-talk/UI/MainWindow.xaml.cs | 37 +++++++------- bibtalk/bib-talk/UI/RegisterWindow.xaml | 3 -- bibtalk/bib-talk/UI/RegisterWindow.xaml.cs | 34 ++++++++----- 15 files changed, 142 insertions(+), 106 deletions(-) diff --git a/bibtalk/bib-talk/Business/LoginManager.cs b/bibtalk/bib-talk/Business/LoginManager.cs index 95eaa54..c46d2bb 100644 --- a/bibtalk/bib-talk/Business/LoginManager.cs +++ b/bibtalk/bib-talk/Business/LoginManager.cs @@ -9,40 +9,44 @@ namespace bib_talk.Business { public class LoginManager { - private LoginDatabase loginDatabase; + private LoginDatabase loginDatabase; // LoginDatabase Objekt initialisieren + // Konstruktor für den LoginManager public LoginManager(Login loginWindow) { - loginDatabase = new LoginDatabase(loginWindow); + loginDatabase = new LoginDatabase(loginWindow); // LoginDatabase Objekt deklarieren } + // Methode zum User einloggen via LoginDatabase public async void Login() { await loginDatabase.LoginServer(); } - public async Task LoginBots(string username, string password) - { - var loginData = new { Username = username, Password = password, Email = "", Birthday = "", IsOnline = "" }; - string json = JsonConvert.SerializeObject(loginData); + // DEBUG METHODE + // Methode um Bots einzuloggen + //public async Task LoginBots(string username, string password) + //{ + // var loginData = new { Username = username, Password = password, Email = "", Birthday = "", IsOnline = "" }; + // string json = JsonConvert.SerializeObject(loginData); - 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/login", content); + // 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/login", content); - if (response.IsSuccessStatusCode) - { - var responseContent = await response.Content.ReadAsStringAsync(); - var responseData = JsonConvert.DeserializeObject(responseContent); + // if (response.IsSuccessStatusCode) + // { + // var responseContent = await response.Content.ReadAsStringAsync(); + // var responseData = JsonConvert.DeserializeObject(responseContent); - } - else - { - var responseContent = await response.Content.ReadAsStringAsync(); - MessageBox.Show($"Login failed: {responseContent}"); - } - } - } + // } + // else + // { + // var responseContent = await response.Content.ReadAsStringAsync(); + // MessageBox.Show($"Login failed: {responseContent}"); + // } + // } + //} } } diff --git a/bibtalk/bib-talk/Business/MainWindowManager.cs b/bibtalk/bib-talk/Business/MainWindowManager.cs index 9b137ba..30e48a1 100644 --- a/bibtalk/bib-talk/Business/MainWindowManager.cs +++ b/bibtalk/bib-talk/Business/MainWindowManager.cs @@ -5,40 +5,41 @@ namespace bib_talk.Business { public class MainWindowManager { - private MainWindowDatabase mwDatabase; - private string loggedinUser; - - public MainWindowManager(MainWindow mainWindow) - { - mwDatabase = new MainWindowDatabase(mainWindow); - } + private MainWindowDatabase mwDatabase; //MainWindowDatabase initializeren + private string loggedInUser; // Feld um eingeloggten User zu speichern + // Konstruktor für MainWindowManager mit MainWindow und User Referenz public MainWindowManager(MainWindow mainWindow, string user) { mwDatabase = new MainWindowDatabase(mainWindow, user); - loggedinUser = user; + loggedInUser = user; } + // Methode zum Senden einer Nachricht via Datenbankmanager public void SendMessage() { mwDatabase.SendMessage(); } + // Methode zum Laden der Nachrichten via Datenbankmanager public void LoadMessages() { mwDatabase.LoadMessages(); } + // Methode zum Laden der Online Benutzer via Datenbankmanager public void LoadOnlineUsers() { mwDatabase.LoadOnlineUsers(); } + // Methode zum Ausloggen des Users via Datenbankmanager public void LogoutUser() { mwDatabase.LogoutUser(); } + // Methode zum Hochladen eines Profilbildes via Datenbankmanager public async Task UploadProfileImage(string filePath) { await mwDatabase.UploadProfileImage(filePath); diff --git a/bibtalk/bib-talk/Business/Message.cs b/bibtalk/bib-talk/Business/Message.cs index 5d94fdc..ed6a214 100644 --- a/bibtalk/bib-talk/Business/Message.cs +++ b/bibtalk/bib-talk/Business/Message.cs @@ -2,6 +2,7 @@ namespace bib_talk.Business { + // Klasse um die Nachrichten in der Datenbank zu speichern public class Message { public int Id { get; set; } diff --git a/bibtalk/bib-talk/Business/MessageDto.cs b/bibtalk/bib-talk/Business/MessageDto.cs index 46fddf2..6247b8e 100644 --- a/bibtalk/bib-talk/Business/MessageDto.cs +++ b/bibtalk/bib-talk/Business/MessageDto.cs @@ -2,6 +2,7 @@ namespace bib_talk.Business { + // Klasse damit die Nachrichten in der App benutzt werden können public class MessageDto { public string Username { get; set; } diff --git a/bibtalk/bib-talk/Business/RegisterManager.cs b/bibtalk/bib-talk/Business/RegisterManager.cs index c370c27..63ac616 100644 --- a/bibtalk/bib-talk/Business/RegisterManager.cs +++ b/bibtalk/bib-talk/Business/RegisterManager.cs @@ -8,18 +8,23 @@ namespace bib_talk.Business { public class RegisterManager { - private RegisterDatabase registerDatabase; + private RegisterDatabase registerDatabase; // RegisterDatabase Objekt initialisieren + // Konstruktor für den RegisterManager public RegisterManager(RegisterWindow registerWindow) { - registerDatabase = new RegisterDatabase(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 = "" }; diff --git a/bibtalk/bib-talk/Business/User.cs b/bibtalk/bib-talk/Business/User.cs index 493f553..bd455bb 100644 --- a/bibtalk/bib-talk/Business/User.cs +++ b/bibtalk/bib-talk/Business/User.cs @@ -1,5 +1,8 @@ namespace bib_talk.Business { + // User Klasse mit den Eigenschaften Id, Username, Password, + // Email, Birthday, IsOnline und ProfileImagePath + // um diese in der App zu Benutzen und in der Datenbank zu speichern public class User { public int Id { get; set; } diff --git a/bibtalk/bib-talk/Repository/LoginDatabase.cs b/bibtalk/bib-talk/Repository/LoginDatabase.cs index b75737f..0e984a9 100644 --- a/bibtalk/bib-talk/Repository/LoginDatabase.cs +++ b/bibtalk/bib-talk/Repository/LoginDatabase.cs @@ -8,13 +8,15 @@ namespace bib_talk.Repository { public class LoginDatabase { - Login loginWindow; + Login loginWindow; // Login Window initialisieren + // Konstruker der LoginDatabase public LoginDatabase(Login loginWindow) { - this.loginWindow = loginWindow; + this.loginWindow = loginWindow; // Login Window deklarieren } + // Methode um den User einzuloggen via eines Server aufrufs public async Task LoginServer() { string username = loginWindow.usernbox.Text; diff --git a/bibtalk/bib-talk/Repository/MainWindowDatabase.cs b/bibtalk/bib-talk/Repository/MainWindowDatabase.cs index 9bd16d1..03c07e6 100644 --- a/bibtalk/bib-talk/Repository/MainWindowDatabase.cs +++ b/bibtalk/bib-talk/Repository/MainWindowDatabase.cs @@ -12,28 +12,25 @@ namespace bib_talk.Repository { public class MainWindowDatabase { - private MainWindow mainWindow; - private string loggedinUser; - - public MainWindowDatabase(MainWindow mainWindow) - { - this.mainWindow = mainWindow; - } + private MainWindow mainWindow; // MainWindow initialisieren + private string loggedinUser; // Feld um eingeloggten User zu speichern + // Konstruktor für MainWindowDatabase mit MainWindow und User Referenz public MainWindowDatabase(MainWindow mainWindow, string user) { this.mainWindow = mainWindow; loggedinUser = user; } + // Methode zum Senden einer Nachricht via Datenbank public async void SendMessage() { - if (!string.IsNullOrEmpty(mainWindow.messageBOX.Text)) + if (!string.IsNullOrEmpty(mainWindow.messageBox.Text)) { var message = new MessageDto { Username = mainWindow.loggedinUser, - Message = mainWindow.messageBOX.Text, + Message = mainWindow.messageBox.Text, Timestamp = DateTime.Now, }; @@ -45,13 +42,14 @@ namespace bib_talk.Repository if (response.IsSuccessStatusCode) { - mainWindow.messageBOX.Clear(); + mainWindow.messageBox.Clear(); LoadMessages(); // Reload messages after sending } } } } + // Methode zum Laden der Nachrichten via Datenbank public async void LoadMessages() { using (var client = new HttpClient()) @@ -71,6 +69,7 @@ namespace bib_talk.Repository } } + // Methode zum Laden der Online Benutzer via Datenbank public async void LoadOnlineUsers() { using (var client = new HttpClient()) @@ -88,6 +87,7 @@ namespace bib_talk.Repository } } + // Methode zum Ausloggen des Users via Datenbank public async void LogoutUser() { using (var client = new HttpClient()) @@ -104,6 +104,7 @@ namespace bib_talk.Repository } } + // Methode zum Hochladen eines Profilbildes via Datenbank public async Task UploadProfileImage(string filePath) { using (var client = new HttpClient()) diff --git a/bibtalk/bib-talk/Repository/RegisterDatabase.cs b/bibtalk/bib-talk/Repository/RegisterDatabase.cs index 460b890..8b1ca12 100644 --- a/bibtalk/bib-talk/Repository/RegisterDatabase.cs +++ b/bibtalk/bib-talk/Repository/RegisterDatabase.cs @@ -8,13 +8,16 @@ namespace bib_talk.Repository { public class RegisterDatabase { - RegisterWindow registerWindow; + 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; diff --git a/bibtalk/bib-talk/UI/Login.xaml b/bibtalk/bib-talk/UI/Login.xaml index afe36d0..58ee227 100644 --- a/bibtalk/bib-talk/UI/Login.xaml +++ b/bibtalk/bib-talk/UI/Login.xaml @@ -101,7 +101,7 @@ Margin="0,30,0,0" Background="#FF323134" Foreground="White" - SelectionBrush="#FF6332A0" KeyDown="usernbox_KeyDown"/> + SelectionBrush="#FF6332A0" KeyDown="userNameBox_KeyDown"/> -