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:
parent
28460e3312
commit
80f2610b04
24
bibtalk/bib-talk/Business/LoginManager.cs
Normal file
24
bibtalk/bib-talk/Business/LoginManager.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
51
bibtalk/bib-talk/Business/MainWindowManager.cs
Normal file
51
bibtalk/bib-talk/Business/MainWindowManager.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
24
bibtalk/bib-talk/Business/RegisterManager.cs
Normal file
24
bibtalk/bib-talk/Business/RegisterManager.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
@ -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,13 +13,20 @@ namespace bib_talk.Repository
|
||||
{
|
||||
public class MainWindowDatabase
|
||||
{
|
||||
MainWindow mainWindow;
|
||||
private MainWindow mainWindow;
|
||||
private string loggedinUser;
|
||||
|
||||
public MainWindowDatabase(MainWindow mainWindow)
|
||||
{
|
||||
this.mainWindow = mainWindow;
|
||||
}
|
||||
|
||||
public MainWindowDatabase(MainWindow mainWindow, string user)
|
||||
{
|
||||
this.mainWindow = mainWindow;
|
||||
loggedinUser = user;
|
||||
}
|
||||
|
||||
public async void SendMessage()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(mainWindow.messageBOX.Text))
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 24 KiB |
@ -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; }
|
||||
|
@ -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();
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
@ -12,9 +12,6 @@
|
||||
<None Remove="logo.png" />
|
||||
<None Remove="Logo_bib-Talk.png" />
|
||||
<None Remove="PICA.jpg" />
|
||||
<None Remove="UI\logo - Copy.png" />
|
||||
<None Remove="UI\logo.png" />
|
||||
<None Remove="UI\Logo_bib-Talk.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -25,9 +22,6 @@
|
||||
<Resource Include="Icons\logo.png" />
|
||||
<Resource Include="Icons\Logo_bib-Talk.png" />
|
||||
<Resource Include="Icons\PICA.jpg" />
|
||||
<Resource Include="UI\logo - Copy.png" />
|
||||
<Resource Include="UI\logo.png" />
|
||||
<Resource Include="UI\Logo_bib-Talk.png" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user