public bool isUsernameUnique(string text) { try { DBBroker broker = new DBBroker(); return(broker.isUsernameUnique(text)); } catch (Exception) { throw; } }
private void btnAddUser_Click(object sender, EventArgs e) { User user = new User(); if (txtUsernam.Text != "") { bool UsernameUnique = broker.isUsernameUnique(txtUsernam.Text); if (UsernameUnique) { user.Username = txtUsernam.Text; } else { MessageBox.Show("Username is not unique"); return; } } else { MessageBox.Show("Username is empty"); return; } if (txtPasword.Text != "") { if (txtPasword.Text == txtConfirmPassword.Text) { user.Password = txtPasword.Text; } else { MessageBox.Show("Passwords must be same"); return; } } else { MessageBox.Show("Password is empty"); return; } if (txtEmail.Text != "") { user.Email = txtEmail.Text; } else { MessageBox.Show("Email is empty"); return; } if (txtName.Text != "") { user.Name = txtName.Text; } else { MessageBox.Show("Name is empty"); return; } if (txtSurname.Text != "") { user.Surname = txtSurname.Text; } else { MessageBox.Show("Surname is empty"); return; } user.Role = (int)cmbRole.SelectedItem; bool pass = broker.createUser(user); if (pass) { MessageBox.Show("User saved successfully"); return; } else { MessageBox.Show("System can't save user"); return; } }
private void btnUpdateUser_Click(object sender, EventArgs e) { if (txtUsernam.Text != "") { bool UsernameUnique = broker.isUsernameUnique(txtUsernam.Text); if (UsernameUnique || txtUsernam.Text == oldUsername) { user.Username = txtUsernam.Text; } else { MessageBox.Show("Username is not unique"); return; } } else { MessageBox.Show("Username is empty"); return; } if (txtPasword.Text != "") { if (txtPasword.Text == txtConfirmPassword.Text) { user.Password = txtPasword.Text; } else { MessageBox.Show("Passwords must be same"); return; } } else { MessageBox.Show("Password is empty"); return; } if (txtEmail.Text != "") { user.Email = txtEmail.Text; } else { MessageBox.Show("Email is empty"); return; } if (txtName.Text != "") { user.Name = txtName.Text; } else { MessageBox.Show("Name is empty"); return; } if (txtSurname.Text != "") { user.Surname = txtSurname.Text; } else { MessageBox.Show("Surname is empty"); return; } if (cmbRole.SelectedItem != null) { user.Role = (int)cmbRole.SelectedItem; } else { MessageBox.Show("Please select a role"); return; } bool pass = broker.updateUser(user, oldUsername); //change username in tasks if (pass) { MessageBox.Show("User updated successfully"); return; } else { MessageBox.Show("System can't update user"); return; } }