public FrmRoleView(AccessToken accessToken, Role role = null) { InitializeComponent(); var RoleAccess = new RoleAccess(accessToken, this); _accessToken = accessToken; _role = role; }
public static bool UpdateRole(Role updatedRole, Role originalRole) { if (originalRole.Id != null) { return RoleDAL.UpdateRole(updatedRole, originalRole); } else { return false; } }
public static bool Add(Role role) { var connection = GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_InsertIntoRoles", connection) { CommandType = CommandType.StoredProcedure }; mySqlCommand.Parameters.AddWithValue("@Title", role.Name); mySqlCommand.Parameters.AddWithValue("@Description", role.Description); mySqlCommand.Parameters.AddWithValue("@Active", role.Active ? 1 : 0); connection.Open(); if (mySqlCommand.ExecuteNonQuery() == 1) { return true; } } #region Exceptions catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { connection.Close(); } #endregion return false; }
public static bool DeactivateRole(Role role) { role.Active = false; return RoleDAL.UpdateActive(role); }
public static bool AddRole(Role role) { return RoleDAL.Add(role); }
public static bool ActivateRole(Role role) { role.Active = true; return RoleDAL.UpdateActive(role); }
private void Save_Button_Click(object sender, EventArgs e) { string errorMessages = "The following errors accured:\n"; switch (Mode) { case "NEW": _role = new Role(0); _role.Name = titleTxb.Text; _role.Description = descTxb.Text; _role.Active = true; if (RoleManager.AddRole(_role)) { MessageBox.Show("Role Added Successfully"); this.Close(); } else { MessageBox.Show("There was an error adding role."); } break; case "EDIT": if (_role.Id > 0) { bool valid = true; if(titleTxb.Text.Length > 25) { valid = false; errorMessages += "Title must be 25 characters or less.\n"; } if (descTxb.Text.Length > 250) { valid = false; errorMessages += "Description must be 250 characters or less.\n"; } if (!valid) { MessageBox.Show(errorMessages); break; } Role editedRole = new Role(_role.Id) { Name = titleTxb.Text, Description = descTxb.Text, Active = true }; try { if (RoleManager.UpdateRole(editedRole, _role)) { this.DialogResult = DialogResult.OK; MessageBox.Show("Role updated"); } else { MessageBox.Show("Error updating role"); } } catch (Exception ex) { MessageBox.Show("Error has Occured. \n Error Message: \n" + ex.Message); } } break; default: break; } }
private void roleCmb_SelectedIndexChanged(object sender, EventArgs e) { SelectedRole = _activeRoles.First(role => role.Id == (int)roleCmb.SelectedValue); }
public static List<Role> GetRolesByActive(Boolean active) { List<Role> roles = new List<Role>(); SqlConnection conn = GetInventoryDbConnection(); try { conn.Open(); SqlCommand sqlCmd = new SqlCommand("proc_GetRolesByActive", conn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@Active", active ? 1 : 0); SqlDataReader reader = sqlCmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var role = new Role(reader.GetInt32(0)) { Name = reader.GetString(reader.GetOrdinal("Name")), Description = reader.GetString(reader.GetOrdinal("Description")), Active = reader.GetBoolean(reader.GetOrdinal("Active")), }; roles.Add(role); } } reader.Close(); } #region Exceptions catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { conn.Close(); } #endregion return roles; }
public static bool AssignRole(CLSEmployee employee, Role role) { //TODO return false; }