//Knapp för att skapa en ny användare private void ButtonSkapa_Click(object sender, RoutedEventArgs e) { if (TextBoxNamn.Text != "" && IsValidEmail(TextBoxEpost.Text)) //If-sats för att kolla så att textboxarna inte är tomma { normalUsersListbox.Items.Add(new User(TextBoxNamn.Text, TextBoxEpost.Text)); TextBoxNamn.Clear(); TextBoxEpost.Clear(); } }
//Knapp för att ändra en vald användare eller admin private void ChangeUser_Click(object sender, RoutedEventArgs e) { if (normalUsersListbox.SelectedIndex >= 0) { if (TextBoxNamn.Text != "" && IsValidEmail(TextBoxEpost.Text)) { normalUsersListbox.Items.Remove(normalUsersListbox.Items[normalUsersListbox.SelectedIndex]); normalUsersListbox.Items.Add(new User(TextBoxNamn.Text, TextBoxEpost.Text)); TextBoxNamn.Clear(); TextBoxEpost.Clear(); } } else if (AdminListBox.SelectedIndex >= 0) { if (TextBoxNamn.Text != "" && IsValidEmail(TextBoxEpost.Text)) { AdminListBox.Items.Remove(AdminListBox.Items[AdminListBox.SelectedIndex]); AdminListBox.Items.Add(new User(TextBoxNamn.Text, TextBoxEpost.Text)); TextBoxNamn.Clear(); TextBoxEpost.Clear(); } } }