59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using CineBook.Models;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace CineBook.Views;
|
|
|
|
public partial class UserEditDialog : Window
|
|
{
|
|
public string Username { get; private set; } = "";
|
|
public string Password { get; private set; } = "";
|
|
public string Role { get; private set; } = "User";
|
|
public string Email { get; private set; } = "";
|
|
|
|
private readonly User? _editing;
|
|
|
|
public UserEditDialog(User? user)
|
|
{
|
|
InitializeComponent();
|
|
_editing = user;
|
|
|
|
if (user != null)
|
|
{
|
|
DialogTitle.Text = "👤 BENUTZER BEARBEITEN";
|
|
UsernameBox.Text = user.Username;
|
|
EmailBox.Text = user.Email;
|
|
foreach (ComboBoxItem item in RoleBox.Items)
|
|
if (item.Content?.ToString() == user.Role)
|
|
RoleBox.SelectedItem = item;
|
|
}
|
|
else
|
|
{
|
|
DialogTitle.Text = "👤 BENUTZER ANLEGEN";
|
|
RoleBox.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
private void SaveClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(UsernameBox.Text) || UsernameBox.Text.Trim().Length < 3)
|
|
{ ErrorText.Text = "⚠ Benutzername mindestens 3 Zeichen!"; return; }
|
|
|
|
if (_editing == null && (string.IsNullOrEmpty(PasswordBox.Password) || PasswordBox.Password.Length < 6))
|
|
{ ErrorText.Text = "⚠ Passwort mindestens 6 Zeichen!"; return; }
|
|
|
|
if (RoleBox.SelectedItem is not ComboBoxItem ri)
|
|
{ ErrorText.Text = "⚠ Rolle auswählen!"; return; }
|
|
|
|
Username = UsernameBox.Text.Trim();
|
|
Password = PasswordBox.Password;
|
|
Role = ri.Content?.ToString() ?? "User";
|
|
Email = EmailBox.Text.Trim();
|
|
|
|
DialogResult = true;
|
|
Close();
|
|
}
|
|
|
|
private void CancelClick(object sender, RoutedEventArgs e) { DialogResult = false; Close(); }
|
|
}
|