private void BtnCreate_Click(object sender, EventArgs e) { try { if (FormLoggedUser.Role.UserRoleId == 2) { MessageBox.Show("You don't have permision to create users", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { usr.Name = txtNameCreate.Text; usr.LastName = txtLastNameCreate.Text; usr.Email = txtEmailCreate.Text; usr.Username = txtUsernameCreate.Text; usr.InsBy = FormLoggedUser.Id; usr.Password = Sec.Hash(usr.Username, txtPasswordCreate.Text); usr._role = getRoleCreate(); usr.RoleID = usr._role.UserRoleId; UsersValidation usrval = new UsersValidation(); ValidationResult vres = usrval.Validate(usr); if (vres.IsValid == false) { foreach (ValidationFailure item in vres.Errors) { errors += $"{item.ErrorMessage} + \n"; } MessageBox.Show(errors); } int error = usrbll.Add(usr); if (error == 0) { this.Close(); } else if (error == 1) { MessageBox.Show("This username alreay exists, please if this user is deactivated you can update it"); } else if (error == -1) { throw new Exception(); } } } catch (FormatException) { MessageBox.Show("User is not valid"); } catch (Exception) { MessageBox.Show("User is not inserted please contact your administrator"); } }
private void ButtonAdd_Click(object sender, EventArgs e) { Users user = new Users(); if (UsersValidation.isValidID(textboxUserID) && UsersValidation.isValidName(textboxPost) && UsersValidation.isValidEmployee(textboxEmpID)) { user.UserID = Convert.ToInt32(textboxUserID.Text); user.Post = textboxPost.Text; user.EmployeeID = Convert.ToInt32(textboxEmpID.Text); UserDA.Add(user); ClearAll(); } }
public ManageUserAccountsForm() { InitializeComponent(); usrval = new UsersValidation(); rolebll = new RoleBLL(); role = rolebll.GetAllRoles(); usr = new User(); usrbll = new UserBLL(); users = new List <User>(); comboRoleCreate.DataSource = role; comboRoleCreate.DisplayMember = "UserRole"; }
public override bool IsValid() { ValidationResult = new UsersValidation().Validate(this.users); return(ValidationResult.IsValid); }