コード例 #1
0
 private DataTable GetAllRoles()
 {
     DataTable dtRole = new DataTable();
     dtRole.Columns.Add("RoleID");
     dtRole.Columns.Add("RoleName");
     dtRole.AcceptChanges();
     RolesManagementController objController = new RolesManagementController();
     List<RolesManagementInfo> objRoles = objController.PortalRoleList(GetPortalID, false, GetUsername);
     foreach (RolesManagementInfo role in objRoles)
     {
         string roleName = role.RoleName;
         if (SystemSetting.SYSTEM_ROLES.Contains(roleName, StringComparer.OrdinalIgnoreCase))
         {
             DataRow dr = dtRole.NewRow();
             dr["RoleID"] = role.RoleId;
             dr["RoleName"] = roleName;
             dtRole.Rows.Add(dr);
         }
         else
         {
             string rolePrefix = GetPortalSEOName + "_";
             roleName = roleName.Replace(rolePrefix, "");
             DataRow dr = dtRole.NewRow();
             dr["RoleID"] = role.RoleId;
             dr["RoleName"] = roleName;
             dtRole.Rows.Add(dr);
         }
     }
     return dtRole;
 }
コード例 #2
0
 protected void gdvUser_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (!e.CommandName.Equals("Page"))
         {
             int rowIndex = int.Parse(e.CommandArgument.ToString());
             if (gdvUser.PageIndex > 0)
             {
                 rowIndex = int.Parse(e.CommandArgument.ToString()) - (gdvUser.PageSize * gdvUser.PageIndex);
             }
             hdnEditUsername.Value = gdvUser.DataKeys[rowIndex]["Username"].ToString();
             hdnEditUserID.Value = gdvUser.DataKeys[rowIndex]["UserId"].ToString();
             if (e.CommandName == "EditUser")
             {
                 string username = gdvUser.DataKeys[rowIndex]["Username"].ToString();
                 string[] userRoles = Roles.GetRolesForUser(username);
                 UserInfo sageUser = m.GetUserDetails(GetPortalID, hdnEditUsername.Value);
                 hdnCurrentEmail.Value = sageUser.Email;
                 txtManageEmail.Text = sageUser.Email;
                 txtManageFirstName.Text = sageUser.FirstName;
                 txtManageLastName.Text = sageUser.LastName;
                 txtManageUsername.Text = sageUser.UserName;
                 chkIsActive.Checked = sageUser.IsApproved == true ? true : false;
                 if (SystemSetting.SYSTEM_USERS.Contains(hdnEditUsername.Value) || hdnEditUsername.Value == GetUsername)
                 {
                     chkIsActive.Enabled = false;
                     chkIsActive.Attributes.Add("class", "disabledClass");
                     tabUserRoles.Visible = false;
                 }
                 else
                 {
                     tabUserRoles.Visible = true;
                 }
                 txtCreatedDate.Text = sageUser.CreatedDate.ToShortDateString();
                 txtLastActivity.Text = sageUser.LastActivityDate.ToShortDateString();
                 txtLastLoginDate.Text = sageUser.LastLoginDate.ToShortDateString();
                 txtLastPasswordChanged.Text = sageUser.LastPasswordChangeDate.ToShortDateString();
                 if (!sageUser.IsApproved)
                 {
                     txtLastActivity.Text = "N/A";
                     txtLastLoginDate.Text = "N/A";
                     txtLastPasswordChanged.Text = "N/A";
                 }
                 lstSelectedRoles.Items.Clear();
                 lstUnselectedRoles.Items.Clear();
                 RolesManagementController objController = new RolesManagementController();
                 List<RolesManagementInfo> objRoles = objController.PortalRoleList(GetPortalID, false, GetUsername);
                 foreach (RolesManagementInfo role in objRoles)
                 {
                     string roleName = role.RoleName;
                     if (SystemSetting.SYSTEM_ROLES.Contains(roleName, StringComparer.OrdinalIgnoreCase))
                     {
                         if (userRoles.Contains(roleName, StringComparer.OrdinalIgnoreCase))
                         {
                             lstSelectedRoles.Items.Add(new ListItem(roleName, roleName));
                         }
                         else
                         {
                             lstUnselectedRoles.Items.Add(new ListItem(roleName, roleName));
                         }
                     }
                     else
                     {
                         if (userRoles.Contains(roleName, StringComparer.OrdinalIgnoreCase))
                         {
                             string rolePrefix = GetPortalSEOName + "_";
                             roleName = roleName.Replace(rolePrefix, "");
                             lstSelectedRoles.Items.Add(new ListItem(roleName, roleName));
                         }
                         else
                         {
                             string rolePrefix = GetPortalSEOName + "_";
                             roleName = roleName.Replace(rolePrefix, "");
                             lstUnselectedRoles.Items.Add(new ListItem(roleName, roleName));
                         }
                     }
                 }
                 if (userRoles.Contains("Super User") && username.ToLower() == "superuser")
                 {
                     btnAddAllRole.Enabled = false;
                     btnAddRole.Enabled = false;
                     btnRemoveAllRole.Enabled = false;
                     btnRemoveRole.Enabled = false;
                     lstUnselectedRoles.Enabled = false;
                     lstSelectedRoles.Enabled = false;
                 }
                 PanelVisibility(false, false, true, false, false);
                 LoadUserProfileData();
             }
             else if (e.CommandName == "DeleteUser")
             {
                 if (hdnEditUsername.Value != "")
                 {
                     UserInfo user = new UserInfo(hdnEditUsername.Value, GetPortalID, Membership.ApplicationName, GetUsername);
                     m.DeleteUser(user);
                     ShowMessage("", GetSageMessage("UserManagement", "UserDeletedSuccessfully"), "", SageMessageType.Success);
                     BindUsers(string.Empty);
                 }
                 else
                 {
                     ShowMessage("", GetSageMessage("UserManagement", "SelectDeleteButtonOnceAgain"), "", SageMessageType.Alert);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
 }
コード例 #3
0
 private void BindRoles()
 {
     try
     {
         DataTable dtRoles = new DataTable();
         dtRoles.Columns.Add("Role");
         dtRoles.Columns.Add("RoleID");
         dtRoles.AcceptChanges();
         RolesManagementController objController = new RolesManagementController();
         List<RolesManagementInfo> objRoles = objController.PortalRoleList(GetPortalID, true, GetUsername);
         foreach (RolesManagementInfo role in objRoles)
         {
             string roleName = role.RoleName;
             if (SystemSetting.SYSTEM_ROLES.Contains(roleName, StringComparer.OrdinalIgnoreCase))
             {
                 DataRow dr = dtRoles.NewRow();
                 dr["Role"] = roleName;
                 dr["RoleID"] = role.RoleId;
                 dtRoles.Rows.Add(dr);
             }
             else
             {
                 string rolePrefix = GetPortalSEOName + "_";
                 roleName = roleName.Replace(rolePrefix, "");
                 DataRow dr = dtRoles.NewRow();
                 dr["Role"] = roleName;
                 dr["RoleID"] = role.RoleId;
                 dtRoles.Rows.Add(dr);
             }
         }
         gdvRoles.DataSource = dtRoles;
         gdvRoles.DataBind();
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
 }