diff --git a/bibtalk/bib-talk/Business/LoginManager.cs b/bibtalk/bib-talk/Business/LoginManager.cs new file mode 100644 index 0000000..2ae823e --- /dev/null +++ b/bibtalk/bib-talk/Business/LoginManager.cs @@ -0,0 +1,24 @@ +using bib_talk.Repository; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bib_talk.Business +{ + public class LoginManager + { + private LoginDatabase loginDatabase; + + public LoginManager(Login loginWindow) + { + loginDatabase = new LoginDatabase(loginWindow); + } + + public async void Login() + { + await loginDatabase.LoginServer(); + } + } +} diff --git a/bibtalk/bib-talk/Business/MainWindowManager.cs b/bibtalk/bib-talk/Business/MainWindowManager.cs new file mode 100644 index 0000000..96f50b9 --- /dev/null +++ b/bibtalk/bib-talk/Business/MainWindowManager.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using bib_talk.Repository; + +namespace bib_talk.Business +{ + public class MainWindowManager + { + private MainWindowDatabase mwDatabase; + private string loggedinUser; + + public MainWindowManager(MainWindow mainWindow) + { + mwDatabase = new MainWindowDatabase(mainWindow); + } + + public MainWindowManager(MainWindow mainWindow, string user) + { + mwDatabase = new MainWindowDatabase(mainWindow, user); + loggedinUser = user; + } + + public void SendMessage() + { + mwDatabase.SendMessage(); + } + + public void LoadMessages() + { + mwDatabase.LoadMessages(); + } + + public void LoadOnlineUsers() + { + mwDatabase.LoadOnlineUsers(); + } + + public void LogoutUser() + { + mwDatabase.LogoutUser(); + } + + public async Task UploadProfileImage(string filePath) + { + await mwDatabase.UploadProfileImage(filePath); + } + } +} diff --git a/bibtalk/bib-talk/Business/RegisterManager.cs b/bibtalk/bib-talk/Business/RegisterManager.cs new file mode 100644 index 0000000..7cb383e --- /dev/null +++ b/bibtalk/bib-talk/Business/RegisterManager.cs @@ -0,0 +1,24 @@ +using bib_talk.Repository; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bib_talk.Business +{ + public class RegisterManager + { + private RegisterDatabase registerDatabase; + + public RegisterManager(RegisterWindow registerWindow) + { + registerDatabase = new RegisterDatabase(registerWindow); + } + + public async void RegisterServer() + { + await registerDatabase.RegisterServer(); + } + } +} diff --git a/bibtalk/bib-talk/Business/readme.txt b/bibtalk/bib-talk/Business/readme.txt deleted file mode 100644 index ac5e280..0000000 --- a/bibtalk/bib-talk/Business/readme.txt +++ /dev/null @@ -1,2 +0,0 @@ -Alle Business Klassen sind die [name].xaml.cs Dateien. -Diese sind NICHT in diesem Ordner, weil wir sie von der [name].xaml Datei nicht trennen können. \ No newline at end of file diff --git a/bibtalk/bib-talk/Repository/MainWindowDatabase.cs b/bibtalk/bib-talk/Repository/MainWindowDatabase.cs index 43f4931..ac2510e 100644 --- a/bibtalk/bib-talk/Repository/MainWindowDatabase.cs +++ b/bibtalk/bib-talk/Repository/MainWindowDatabase.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Net.Http; using System.Text; @@ -12,11 +13,18 @@ namespace bib_talk.Repository { public class MainWindowDatabase { - MainWindow mainWindow; + private MainWindow mainWindow; + private string loggedinUser; - public MainWindowDatabase(MainWindow mainWindow) + public MainWindowDatabase(MainWindow mainWindow) + { + this.mainWindow = mainWindow; + } + + public MainWindowDatabase(MainWindow mainWindow, string user) { this.mainWindow = mainWindow; + loggedinUser = user; } public async void SendMessage() @@ -81,9 +89,6 @@ namespace bib_talk.Repository } } - - - public async void LogoutUser() { using (var client = new HttpClient()) @@ -99,5 +104,25 @@ namespace bib_talk.Repository mainWindow.Close(); } } - } + + public async Task UploadProfileImage(string filePath) + { + using (var client = new HttpClient()) + { + var form = new MultipartFormDataContent(); + var stream = File.OpenRead(filePath); + form.Add(new StreamContent(stream), "file", Path.GetFileName(filePath)); + + var response = await client.PostAsync($"http://daddypig.dns.navy:5114/api/users/upload-profile-image?username={loggedinUser}", form); + if (response.IsSuccessStatusCode) + { + MessageBox.Show("Profilbild erfolgreich hochgeladen"); + } + else + { + MessageBox.Show("Fehler beim Hochladen des Profilbilds"); + } + } + } + } } diff --git a/bibtalk/bib-talk/UI/Login.xaml.cs b/bibtalk/bib-talk/UI/Login.xaml.cs index a734283..0ac77f5 100644 --- a/bibtalk/bib-talk/UI/Login.xaml.cs +++ b/bibtalk/bib-talk/UI/Login.xaml.cs @@ -5,14 +5,14 @@ using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Media; using System.Windows; +using bib_talk.Business; using bib_talk.Repository; namespace bib_talk { public partial class Login : Window { - LoginDatabase loginDatabase; - + LoginManager loginManager; // Field to store logged in user public static string loggedInUser; @@ -21,7 +21,7 @@ namespace bib_talk { InitializeComponent(); - loginDatabase = new LoginDatabase(this); + loginManager = new LoginManager(this); } private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) @@ -48,9 +48,7 @@ namespace bib_talk { if (usernbox.Text != "" && passwordbox.Password != "") { - - await loginDatabase.LoginServer(); - + loginManager.Login(); } } diff --git a/bibtalk/bib-talk/UI/Logo_bib-Talk.png b/bibtalk/bib-talk/UI/Logo_bib-Talk.png deleted file mode 100644 index 00fbd91..0000000 Binary files a/bibtalk/bib-talk/UI/Logo_bib-Talk.png and /dev/null differ diff --git a/bibtalk/bib-talk/UI/MainWindow.xaml.cs b/bibtalk/bib-talk/UI/MainWindow.xaml.cs index e0eaa17..8132844 100644 --- a/bibtalk/bib-talk/UI/MainWindow.xaml.cs +++ b/bibtalk/bib-talk/UI/MainWindow.xaml.cs @@ -14,12 +14,13 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; +using bib_talk.Business; namespace bib_talk { public partial class MainWindow : Window { - MainWindowDatabase database; + MainWindowManager mwManager; private DispatcherTimer _timer; public string loggedinUser; @@ -31,7 +32,7 @@ namespace bib_talk InitializeTimer(); LoadData(); - database = new MainWindowDatabase(this); + mwManager = new MainWindowManager(this); } public MainWindow(string user) @@ -41,9 +42,9 @@ namespace bib_talk InitializeTimer(); LoadData(); - database = new MainWindowDatabase(this); + mwManager = new MainWindowManager(this, user); - database.LoadMessages(); + mwManager.LoadMessages(); } private void InitializeTimer() @@ -52,7 +53,7 @@ namespace bib_talk { Interval = TimeSpan.FromSeconds(2) }; - _timer.Tick += (sender, e) => { database.LoadMessages(); database.LoadOnlineUsers(); }; + _timer.Tick += (sender, e) => { mwManager.LoadMessages(); mwManager.LoadOnlineUsers(); }; _timer.Start(); } public void LoadData() @@ -62,7 +63,7 @@ namespace bib_talk private void CloseButton_Click(object sender, RoutedEventArgs e) { - database.LogoutUser(); + mwManager.LogoutUser(); this.Close(); } @@ -78,13 +79,13 @@ namespace bib_talk { if (e.Key == Key.Enter) { - database.SendMessage(); + mwManager.SendMessage(); } } private async void send_Click(object sender, RoutedEventArgs e) { - database.SendMessage(); + mwManager.SendMessage(); } private void ChatFenster_Click(object sender, RoutedEventArgs e) @@ -139,27 +140,7 @@ namespace bib_talk if (openFileDialog.ShowDialog() == true) { string filePath = openFileDialog.FileName; - await UploadProfileImage(filePath); - } - } - - private async Task UploadProfileImage(string filePath) - { - using (var client = new HttpClient()) - { - var form = new MultipartFormDataContent(); - var stream = File.OpenRead(filePath); - form.Add(new StreamContent(stream), "file", Path.GetFileName(filePath)); - - var response = await client.PostAsync($"http://daddypig.dns.navy:5114/api/users/upload-profile-image?username={loggedinUser}", form); - if (response.IsSuccessStatusCode) - { - MessageBox.Show("Profilbild erfolgreich hochgeladen"); - } - else - { - MessageBox.Show("Fehler beim Hochladen des Profilbilds"); - } + await mwManager.UploadProfileImage(filePath); } } } @@ -174,12 +155,14 @@ namespace bib_talk public string Text { get; set; } public DateTime Timestamp { get; set; } } + public class MessageDto { public string Username { get; set; } public string Message { get; set; } public DateTime Timestamp { get; set; } } + public class User { public int Id { get; set; } diff --git a/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs b/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs index 5781205..8c9a078 100644 --- a/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs +++ b/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs @@ -17,14 +17,19 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using bib_talk.Business; namespace bib_talk { public partial class RegisterWindow : Window { + RegisterManager registerManager; + public RegisterWindow() { InitializeComponent(); + + registerManager = new RegisterManager(this); } private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) @@ -59,9 +64,9 @@ namespace bib_talk { if (ValidateRegistration()) { - RegisterDatabase registerDatabase = new RegisterDatabase(this); + // Business Schicht Aufruf + registerManager.RegisterServer(); - await registerDatabase.RegisterServer(); Login login = new Login(); login.Show(); this.Close(); diff --git a/bibtalk/bib-talk/UI/logo - Copy.png b/bibtalk/bib-talk/UI/logo - Copy.png deleted file mode 100644 index b7ff500..0000000 Binary files a/bibtalk/bib-talk/UI/logo - Copy.png and /dev/null differ diff --git a/bibtalk/bib-talk/UI/logo.png b/bibtalk/bib-talk/UI/logo.png deleted file mode 100644 index b7ff500..0000000 Binary files a/bibtalk/bib-talk/UI/logo.png and /dev/null differ diff --git a/bibtalk/bib-talk/bib-talk.csproj b/bibtalk/bib-talk/bib-talk.csproj index 0d91ae4..5370b4f 100644 --- a/bibtalk/bib-talk/bib-talk.csproj +++ b/bibtalk/bib-talk/bib-talk.csproj @@ -12,9 +12,6 @@ - - - @@ -25,9 +22,6 @@ - - -