3 Schichten Architektur voll

Erik hat die 3 Schichten arschitektur voll fertig gemacht

wenn jemand sachen added OHNE sie zu beachten gibts stress
This commit is contained in:
Erik 2024-07-03 15:58:51 +02:00
parent 28460e3312
commit 80f2610b04
12 changed files with 153 additions and 51 deletions

View File

@ -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();
}
}
}

View File

@ -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);
}
}
}

View File

@ -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();
}
}
}

View File

@ -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.

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
@ -12,13 +13,20 @@ namespace bib_talk.Repository
{ {
public class MainWindowDatabase public class MainWindowDatabase
{ {
MainWindow mainWindow; private MainWindow mainWindow;
private string loggedinUser;
public MainWindowDatabase(MainWindow mainWindow) public MainWindowDatabase(MainWindow mainWindow)
{ {
this.mainWindow = mainWindow; this.mainWindow = mainWindow;
} }
public MainWindowDatabase(MainWindow mainWindow, string user)
{
this.mainWindow = mainWindow;
loggedinUser = user;
}
public async void SendMessage() public async void SendMessage()
{ {
if (!string.IsNullOrEmpty(mainWindow.messageBOX.Text)) if (!string.IsNullOrEmpty(mainWindow.messageBOX.Text))
@ -81,9 +89,6 @@ namespace bib_talk.Repository
} }
} }
public async void LogoutUser() public async void LogoutUser()
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
@ -99,5 +104,25 @@ namespace bib_talk.Repository
mainWindow.Close(); 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");
}
}
}
} }
} }

View File

@ -5,14 +5,14 @@ using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows; using System.Windows;
using bib_talk.Business;
using bib_talk.Repository; using bib_talk.Repository;
namespace bib_talk namespace bib_talk
{ {
public partial class Login : Window public partial class Login : Window
{ {
LoginDatabase loginDatabase; LoginManager loginManager;
// Field to store logged in user // Field to store logged in user
public static string loggedInUser; public static string loggedInUser;
@ -21,7 +21,7 @@ namespace bib_talk
{ {
InitializeComponent(); InitializeComponent();
loginDatabase = new LoginDatabase(this); loginManager = new LoginManager(this);
} }
private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
@ -48,9 +48,7 @@ namespace bib_talk
{ {
if (usernbox.Text != "" && passwordbox.Password != "") if (usernbox.Text != "" && passwordbox.Password != "")
{ {
loginManager.Login();
await loginDatabase.LoginServer();
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@ -14,12 +14,13 @@ using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading; using System.Windows.Threading;
using bib_talk.Business;
namespace bib_talk namespace bib_talk
{ {
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
MainWindowDatabase database; MainWindowManager mwManager;
private DispatcherTimer _timer; private DispatcherTimer _timer;
public string loggedinUser; public string loggedinUser;
@ -31,7 +32,7 @@ namespace bib_talk
InitializeTimer(); InitializeTimer();
LoadData(); LoadData();
database = new MainWindowDatabase(this); mwManager = new MainWindowManager(this);
} }
public MainWindow(string user) public MainWindow(string user)
@ -41,9 +42,9 @@ namespace bib_talk
InitializeTimer(); InitializeTimer();
LoadData(); LoadData();
database = new MainWindowDatabase(this); mwManager = new MainWindowManager(this, user);
database.LoadMessages(); mwManager.LoadMessages();
} }
private void InitializeTimer() private void InitializeTimer()
@ -52,7 +53,7 @@ namespace bib_talk
{ {
Interval = TimeSpan.FromSeconds(2) Interval = TimeSpan.FromSeconds(2)
}; };
_timer.Tick += (sender, e) => { database.LoadMessages(); database.LoadOnlineUsers(); }; _timer.Tick += (sender, e) => { mwManager.LoadMessages(); mwManager.LoadOnlineUsers(); };
_timer.Start(); _timer.Start();
} }
public void LoadData() public void LoadData()
@ -62,7 +63,7 @@ namespace bib_talk
private void CloseButton_Click(object sender, RoutedEventArgs e) private void CloseButton_Click(object sender, RoutedEventArgs e)
{ {
database.LogoutUser(); mwManager.LogoutUser();
this.Close(); this.Close();
} }
@ -78,13 +79,13 @@ namespace bib_talk
{ {
if (e.Key == Key.Enter) if (e.Key == Key.Enter)
{ {
database.SendMessage(); mwManager.SendMessage();
} }
} }
private async void send_Click(object sender, RoutedEventArgs e) private async void send_Click(object sender, RoutedEventArgs e)
{ {
database.SendMessage(); mwManager.SendMessage();
} }
private void ChatFenster_Click(object sender, RoutedEventArgs e) private void ChatFenster_Click(object sender, RoutedEventArgs e)
@ -139,27 +140,7 @@ namespace bib_talk
if (openFileDialog.ShowDialog() == true) if (openFileDialog.ShowDialog() == true)
{ {
string filePath = openFileDialog.FileName; string filePath = openFileDialog.FileName;
await UploadProfileImage(filePath); await mwManager.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");
}
} }
} }
} }
@ -174,12 +155,14 @@ namespace bib_talk
public string Text { get; set; } public string Text { get; set; }
public DateTime Timestamp { get; set; } public DateTime Timestamp { get; set; }
} }
public class MessageDto public class MessageDto
{ {
public string Username { get; set; } public string Username { get; set; }
public string Message { get; set; } public string Message { get; set; }
public DateTime Timestamp { get; set; } public DateTime Timestamp { get; set; }
} }
public class User public class User
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@ -17,14 +17,19 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using bib_talk.Business;
namespace bib_talk namespace bib_talk
{ {
public partial class RegisterWindow : Window public partial class RegisterWindow : Window
{ {
RegisterManager registerManager;
public RegisterWindow() public RegisterWindow()
{ {
InitializeComponent(); InitializeComponent();
registerManager = new RegisterManager(this);
} }
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
@ -59,9 +64,9 @@ namespace bib_talk
{ {
if (ValidateRegistration()) if (ValidateRegistration())
{ {
RegisterDatabase registerDatabase = new RegisterDatabase(this); // Business Schicht Aufruf
registerManager.RegisterServer();
await registerDatabase.RegisterServer();
Login login = new Login(); Login login = new Login();
login.Show(); login.Show();
this.Close(); this.Close();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

View File

@ -12,9 +12,6 @@
<None Remove="logo.png" /> <None Remove="logo.png" />
<None Remove="Logo_bib-Talk.png" /> <None Remove="Logo_bib-Talk.png" />
<None Remove="PICA.jpg" /> <None Remove="PICA.jpg" />
<None Remove="UI\logo - Copy.png" />
<None Remove="UI\logo.png" />
<None Remove="UI\Logo_bib-Talk.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -25,9 +22,6 @@
<Resource Include="Icons\logo.png" /> <Resource Include="Icons\logo.png" />
<Resource Include="Icons\Logo_bib-Talk.png" /> <Resource Include="Icons\Logo_bib-Talk.png" />
<Resource Include="Icons\PICA.jpg" /> <Resource Include="Icons\PICA.jpg" />
<Resource Include="UI\logo - Copy.png" />
<Resource Include="UI\logo.png" />
<Resource Include="UI\Logo_bib-Talk.png" />
</ItemGroup> </ItemGroup>
</Project> </Project>