public bool createUser(User user) { try { DBBroker broker = new DBBroker(); return(broker.createUser(user)); } 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; } }