示例#1
0
        public FrmRoleView(AccessToken accessToken, Role role = null)
        {
            InitializeComponent();
            var RoleAccess = new RoleAccess(accessToken, this);

            _accessToken = accessToken;
            _role = role;
        }
示例#2
0
 public static bool UpdateRole(Role updatedRole, Role originalRole)
 {
     if (originalRole.Id != null)
     {
         return RoleDAL.UpdateRole(updatedRole, originalRole);
     }
     else
     {
         return false;
     }
 }
示例#3
0
        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;
        }
示例#4
0
 public static bool DeactivateRole(Role role)
 {
     role.Active = false;
     return RoleDAL.UpdateActive(role);
 }
示例#5
0
 public static bool AddRole(Role role)
 {
     return RoleDAL.Add(role);
 }
示例#6
0
 public static bool ActivateRole(Role role)
 {
     role.Active = true;
     return RoleDAL.UpdateActive(role);
 }
示例#7
0
        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;
            }
        }
示例#8
0
 private void roleCmb_SelectedIndexChanged(object sender, EventArgs e)
 {
     SelectedRole = _activeRoles.First(role => role.Id == (int)roleCmb.SelectedValue);
 }
示例#9
0
        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;
        }
示例#10
0
 public static bool AssignRole(CLSEmployee employee, Role role)
 {
     //TODO
     return false;
 }