Ejemplo n.º 1
0
        protected void gdvUser_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int    rownum   = Convert.ToInt32(e.CommandArgument);
                string username = gdvUser.DataKeys[rownum]["Username"].ToString();
                string userId   = gdvUser.DataKeys[rownum]["UserId"].ToString();

                hdnEditUsername.Value = username;
                hdnEditUserID.Value   = userId;

                switch (e.CommandName)
                {
                case "EditUser":
                    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");
                    }

                    txtCreatedDate.Text         = sageUser.AddedOn.ToString();
                    txtLastActivity.Text        = sageUser.LastActivityDate.ToShortDateString();
                    txtLastLoginDate.Text       = sageUser.LastLoginDate.ToShortDateString();
                    txtLastPasswordChanged.Text = sageUser.LastPasswordChangeDate.ToShortDateString();
                    lstSelectedRoles.Items.Clear();
                    lstUnselectedRoles.Items.Clear();
                    RolesManagementDataContext dbRoles = new RolesManagementDataContext(SystemSetting.SageFrameConnectionString);
                    var roles = dbRoles.sp_PortalRoleList(GetPortalID, false, GetUsername);
                    foreach (var role in roles)
                    {
                        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));
                            }
                        }
                    }
                    PanelVisibility(false, false, true);
                    userProfile1.EditUserName = hdnEditUsername.Value;
                    break;

                case "DeleteUser":
                    if (hdnEditUsername.Value != "")
                    {
                        UserInfo user = new UserInfo(hdnEditUsername.Value, GetPortalID, Membership.ApplicationName, GetUsername, GetStoreID);
                        m.DeleteUser(user);
                        ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("UserManagement", "UserDeletedSuccessfully"), "", SageMessageType.Success);
                        BindUsers(string.Empty);
                    }
                    else
                    {
                        ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "SelectDeleteButtonOnceAgain"), "", SageMessageType.Alert);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }