Example #1
0
        /// <summary>
        /// Fill the listbox with all the roles that are in the database
        /// </summary>

        public void FillUserRoles()
        {
            RoleLogic Logic = new RoleLogic();

            var AllRoles = Logic.RetrieveAllRoles();

            foreach (var SingleRole in AllRoles)
            {
                CB_Roles.Items.Add(SingleRole.RetrieveRoleName());
            }
        }
Example #2
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            //Get the rolename and the permissionname
            string RoleName       = cmbRoles.SelectedItem.ToString();
            string PermissionName = listBox1.SelectedItem.ToString();

            //New instance of permissionlogic and rolelogic
            PermissionLogic PLogic = new PermissionLogic();
            RoleLogic       RLogic = new RoleLogic();

            //New role and new permisson
            Role       r = new Role(RoleName, 1);
            Permission p = new Permission(1, PermissionName);

            //Empt roleid and permissionid
            int RoleID       = 0;
            int PermissionID = 0;

            //Get permissionid from the database
            var AllPermissions = PLogic.RetrieveAllPermissions();

            foreach (var SinglePermission in AllPermissions)
            {
                if (SinglePermission.PermissionName == p.PermissionName)
                {
                    PermissionID = SinglePermission.RetrievePermissionID();
                }
            }

            //Get roleid from the database
            var AllRoles = RLogic.RetrieveAllRoles();

            foreach (var SingleRole in AllRoles)
            {
                if (SingleRole.RetrieveRoleName() == r.RetrieveRoleName())
                {
                    RoleID = SingleRole.RetrieveRoleID();
                }
            }

            PLogic.DeleteRolePermission(RoleID, PermissionID);

            listBox1.Items.Clear();
            string rol = cmbRoles.SelectedItem.ToString();

            List <string> permissions = PLogic.GetAllRolePermissions(rol);

            foreach (string per in permissions)
            {
                listBox1.Items.Add(per);
            }
        }