Ejemplo n.º 1
0
        /// <summary>
        /// The RolesList_ItemCommand server event handler on this page
        /// is used to handle the user editing and deleting roles
        /// from the RolesList asp:datalist control
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListCommandEventArgs"/> instance containing the event data.</param>
        protected void rolesList_ItemCommand(object source, DataListCommandEventArgs e)
        {
            //http://sourceforge.net/tracker/index.php?func=detail&aid=828580&group_id=66837&atid=515929
            UsersDB users = new UsersDB();

            bool enable = true; // enable add - bja

            if (e.CommandName == "edit")
            {
                // Set editable list item index if "edit" button clicked next to the item
                rolesList.EditItemIndex = e.Item.ItemIndex;
                // disable the add function
                enable = false;
                // Repopulate the datalist control
                BindData();
            }

            else if (e.CommandName == "apply")
            {
                var _roleName = ((TextBox)e.Item.FindControl("roleName")).Text;
                var _roleId   = ((System.Web.UI.WebControls.Label)e.Item.FindControl("roleId")).Text;

                // update database
                users.UpdateRole(new Guid(_roleId), _roleName, this.PortalSettings.PortalAlias);

                // Disable editable list item access
                rolesList.EditItemIndex = -1;

                // Repopulate the datalist control
                BindData();
            }
            else if (e.CommandName == "delete")
            {
                // [email protected]: 30th May 2004: Added Try And Catch To Delete Role
                // update database
                try
                {
                    users.DeleteRole(new Guid(e.CommandArgument.ToString()), this.PortalSettings.PortalAlias);
                }
                catch
                {
                    labelError.Visible = true;
                }
                // End of [email protected] Update

                // Ensure that item is not editable
                rolesList.EditItemIndex = -1;

                // Repopulate list
                BindData();
            }
            else if (e.CommandName == "members")
            {
                string _roleId = ((System.Web.UI.WebControls.Label)e.Item.FindControl("roleId")).Text;

                // Role names shouldn't be editable, it's not supported by the Roles Provider API
                //// Save role name changes first
                //users.UpdateRole( selectedRole.Id, _roleName, portalSettings.PortalAlias );

                // redirect to edit page
                Response.Redirect(
                    HttpUrlBuilder.BuildUrl("~/DesktopModules/CoreModules/Roles/SecurityRoles.aspx", PageID,
                                            "mID=" + ModuleID.ToString() + "&roleID=" + _roleId));
            }
            // reset the enable state of the add
            // set add button -- bja
            AddRoleBtn.Enabled = enable;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The RolesList_ItemCommand server event handler on this page
        /// is used to handle the user editing and deleting roles
        /// from the RolesList asp:datalist control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RolesList_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            //http://sourceforge.net/tracker/index.php?func=detail&aid=828580&group_id=66837&atid=515929
            UsersDB users  = new UsersDB();
            int     roleID = (int)rolesList.DataKeys[e.Item.ItemIndex];
            bool    enable = true;          // enable add - bja

            if (e.CommandName == "edit")
            {
                // Set editable list item index if "edit" button clicked next to the item
                rolesList.EditItemIndex = e.Item.ItemIndex;
                // disable the add function
                enable = false;
                // Repopulate the datalist control
                BindData();
            }

            else if (e.CommandName == "apply")
            {
                // Apply changes
                string _roleName = ((TextBox)e.Item.FindControl("roleName")).Text;

                // update database
                users.UpdateRole(roleID, _roleName);

                // Disable editable list item access
                rolesList.EditItemIndex = -1;

                // Repopulate the datalist control
                BindData();
            }
            else if (e.CommandName == "delete")
            {
                // [email protected]: 30th May 2004: Added Try And Catch To Delete Role
                // update database
                try
                {
                    users.DeleteRole(roleID);
                }
                catch
                {
                    labelError.Visible = true;
                }
                // End of [email protected] Update

                // Ensure that item is not editable
                rolesList.EditItemIndex = -1;

                // Repopulate list
                BindData();
            }
            else if (e.CommandName == "members")
            {
                // Save role name changes first
                string _roleName = ((TextBox)e.Item.FindControl("roleName")).Text;
                users.UpdateRole(roleID, _roleName);

                // redirect to edit page
                Response.Redirect(HttpUrlBuilder.BuildUrl("~/DesktopModules/Roles/SecurityRoles.aspx", TabID, "mID=" + ModuleID.ToString() + "&roleID=" + roleID + "&rolename=" + _roleName));
            }
            // reset the enable state of the add
            // set add button -- bja
            AddRoleBtn.Enabled = enable;
        }