Task done

This commit is contained in:
2025-09-27 23:01:24 +02:00
parent 6c5579809d
commit 6fb3ffb680
8 changed files with 95 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
using Adw;
using GLib;
using Logic;
using Models;
namespace Feladat1.UI.MainWindow;
@@ -22,8 +24,18 @@ public class MainWindow
private PasswordEntryRow passwordField;
private const string passwordFieldId = "password";
public MainWindow()
private EntryRow emailLabel;
private const string emailLabelId = "emailLabel";
private EntryRow usernameLabel;
private const string usernameLabelId = "usernameLabel";
private PasswordEntryRow passwordLabel;
private const string passwordLabelId = "passwordLabel";
public MainWindow(IUserService userService)
{
this.userService = userService;
var builder = new Gtk.Builder("Feladat1.UI.MainWindow.MainWindow.ui.xml");
Window = builder.GetObject(windowId) as Window;
@@ -58,6 +70,24 @@ public class MainWindow
{
throw new NullReferenceException(passwordFieldId);
}
emailLabel = builder.GetObject(emailLabelId) as EntryRow;
if (emailLabel == null)
{
throw new NullReferenceException(emailLabelId);
}
usernameLabel = builder.GetObject(usernameLabelId) as EntryRow;
if (usernameLabel == null)
{
throw new NullReferenceException(usernameLabelId);
}
passwordLabel = builder.GetObject(passwordLabelId) as PasswordEntryRow;
if (passwordLabel == null)
{
throw new NullReferenceException(passwordLabelId);
}
}
catch (NullReferenceException e)
{
@@ -68,7 +98,7 @@ public class MainWindow
private bool ValidateFields()
{
if (userNameField.Text_ != null && emailField.Text_ != null && passwordField.Text_ != null)
if (userNameField.Text_ != string.Empty && emailField.Text_ != string.Empty && passwordField.Text_ != string.Empty)
{
return true;
}
@@ -79,7 +109,22 @@ public class MainWindow
{
if (ValidateFields())
{
userService.Create(userNameField.GetText(), emailField.GetText(), passwordField.GetText());
int returnCode = userService.Create(userNameField.GetText(), emailField.GetText(), passwordField.GetText());
if (returnCode == 0)
{
ToastOverlay overlay = new ToastOverlay();
overlay.SetParent(Window);
Toast toast = new Toast();
toast.SetButtonLabel("New user exported successfully");
overlay.AddToast(toast);
User user = userService.Read();
emailLabel.Text_ = user.Email;
usernameLabel.Text_ = user.Username;
passwordLabel.Text_ = user.Password;
}
}
}
}