Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            m_RoleID = _Request.Get <Guid>("roleid", Method.Get, Guid.Empty);

            if (m_RoleID == Guid.Empty)
            {
                m_Role   = AllSettings.Current.RoleSettings.GetManagerRoles()[0];
                m_RoleID = m_Role.RoleID;
            }
            else
            {
                m_Role = RoleSettings.GetRole(m_RoleID);
            }

            if (m_Role == null)
            {
                ShowError(new InvalidParamError("roleid"));
                return;
            }

            if (_Request.IsClick("savepermission"))
            {
                SavePermission();
            }
        }
Esempio n. 2
0
        public bool SaveSettings()
        {
            MessageDisplay msdDisplay = CreateMessageDisplay("name", "title", "requiredPoint", "level");
            RoleCollection tempRoles  = new RoleCollection();

            RoleSettings settings = SettingManager.CloneSetttings <RoleSettings>(AllSettings.Current.RoleSettings);

            Role temp;

            Guid[] oldRoleids = _Request.GetList <Guid>("roleid", Method.Post, new Guid[00]);

            foreach (Guid r in oldRoleids)
            {
                temp = settings.GetRole(r);

                if (AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.ActionWithTarget.Setting_Roles_Manager, temp))
                {
                    temp = temp == null?CreateRole() : temp.Clone();   //不采用克隆的话可能会有些属性丢失掉

                    temp.Name            = _Request.Get("Name." + r, Method.Post);
                    temp.Title           = _Request.Get("title." + r, Method.Post);
                    temp.RequiredPoint   = _Request.Get <int>("RequiredPoint." + r, Method.Post, 0);
                    temp.Color           = _Request.Get("Color." + r, Method.Post);
                    temp.IconUrlSrc      = _Request.Get("IconUrl." + r, Method.Post);
                    temp.StarLevel       = _Request.Get <int>("StarLevel." + r, Method.Post, 0);
                    temp.Level           = _Request.Get <int>("Level." + r, Method.Post, 0);
                    temp.IsNew           = _Request.Get <bool>("isnew." + r, Method.Post, false);
                    temp.CanLoginConsole = _Request.Get <bool>("CanLoginConsole." + r, Method.Post, false) && temp.IsManager;
                    temp.RoleID          = r;
                    if (temp.IsLevel)
                    {
                        temp.Name = temp.Title;
                    }
                }
                else
                {
                    if (temp == null)
                    {
                        continue;
                    }
                }

                tempRoles.Add(temp);
            }

            //Nonsupport Javascript
            if (_Request.Get("newroleid", Method.Post, "").Contains("{0}"))
            {
                Role r = CreateRole();
                r.Name            = _Request.Get("name.new.{0}", Method.Post);
                r.Title           = _Request.Get("title.new.{0}", Method.Post);
                r.StarLevel       = _Request.Get <int>("starlevel.new.{0}", Method.Post, 0);
                r.RequiredPoint   = _Request.Get <int>("RequiredPoint.new.{0}", Method.Post, 0);
                r.Color           = _Request.Get("color.new.{0}", Method.Post);
                r.IconUrlSrc      = _Request.Get("IconUrl.new.{0}", Method.Post);
                r.Level           = _Request.Get <int>("Level.new.{0}", Method.Post, 0);
                r.CanLoginConsole = _Request.Get <bool>("CanLoginConsole.new.{0}", Method.Post, false) && r.IsManager;
                if (r.IsLevel)
                {
                    r.Name = r.Title;
                }
                if (!string.IsNullOrEmpty(r.Name))
                {
                    tempRoles.Add(r);
                }
            }
            else
            {
                int[] newroleid = _Request.GetList <int>("newroleid", Method.Post, new int[0]);

                foreach (int i in newroleid)
                {
                    Role r = CreateRole();
                    r.Name            = _Request.Get("name.new." + i, Method.Post);
                    r.Title           = _Request.Get("title.new." + i, Method.Post);
                    r.StarLevel       = _Request.Get <int>("starlevel.new." + i, Method.Post, 0);
                    r.RequiredPoint   = _Request.Get <int>("RequiredPoint.new." + i, Method.Post, 0);
                    r.Color           = _Request.Get("color.new." + i, Method.Post);
                    r.IconUrlSrc      = _Request.Get("IconUrl.new." + i, Method.Post);
                    r.Level           = _Request.Get <int>("Level.new." + i, Method.Post, 0);
                    r.CanLoginConsole = _Request.Get <bool>("CanLoginConsole.new." + i, Method.Post, false) && r.IsManager;
                    if (r.IsLevel)
                    {
                        r.Name = r.Title;
                    }
                    tempRoles.Add(r);
                }
            }

            if (ValidateRoleDate(tempRoles, msdDisplay))
            {
                foreach (Role r in tempRoles)
                {
                    settings.SetRole(r);
                }

                if (BeforeSaveSettings(settings))
                {
                    SettingManager.SaveSettings(settings);
                    m_RoleList = null;
                    return(true);
                }
            }

            m_RoleList = tempRoles;
            msdDisplay.AddError(new DataNoSaveError());
            return(false);
        }