Esempio 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;
        }