Example #1
0
        /// <summary>
        /// 根据编辑的菜单项更新角色的访问
        /// </summary>
        /// <param name="obj"></param>
        private void UpdateRole(TB_Permission obj)
        {
            // 更新默认角色可以访问的
            if (obj.IsDefault == true)
            {
                var dftPermission = PermissionInstance.GetDefaultMenus();
                // 查找非管理角色
                var roles = RoleInstance.FindList(f => f.IsAdministrator == false && f.Delete == false);
                foreach (var role in roles)
                {
                    var pers = role.Permission.Split(new char[] { ',' });
                    if (!pers.Contains(obj.id.ToString()))
                    {
                        RoleInstance.Update(f => f.id == role.id, act => act.Permission = dftPermission);
                    }
                }
            }
            // 查找更新管理员角色的访问权限
            RoleInstance.Update(f => f.IsAdministrator == true && f.Delete == false,
                                act => act.Permission = PermissionInstance.GetAdministratorsMenus());

            // 重置当前登陆者的session
            Account = AccountInstance.Find(f => f.id == Account.id);
            Session[Utility.SessionName] = Account;
        }
Example #2
0
        private void New()
        {
            var per = new TB_Permission();

            per.Name      = txtName.Value.Trim();
            per.Image     = hidImage.Value;
            per.Delete    = false;
            per.IsDefault = isDefault.Checked;
            per.Url       = txtURL.Value.Trim();
            // 父级菜单,为空时默认为顶级菜单
            var parent = int.Parse("" == hidParent.Value ? "0" : hidParent.Value);

            per.Parent = parent;
            var brothers = PermissionInstance.FindList(p => p.Parent == parent);

            per.DisplayOrder = brothers.Count();
            per.AddTime      = DateTime.Now;
            per.Description  = txtDescription.Value.Trim();
            PermissionInstance.Add(per);

            // 记录历史
            SaveHistory(new TB_AccountHistory
            {
                ActionId = ActionInstance.Find(f => f.Name.Equals("AddPermission")).id,
                ObjectA  = "[id=" + per.id + "] " + per.Name
            });
            UpdateRole(per);
            ShowNotification("./permission_list.aspx", "Success: You added a new menu.", true);
        }
Example #3
0
 /// <summary>
 /// 更改显示顺序
 /// </summary>
 /// <param name="ord">原始项目</param>
 /// <param name="brother">附近的兄弟项目</param>
 /// <param name="toupper">true=向上调整,false=向下调整</param>
 private void ChangeDisplayOrder(TB_Permission ord, TB_Permission brother, bool toupper)
 {
     if (null != brother)
     {
         brother.DisplayOrder = toupper ? (brother.DisplayOrder + 1) : (brother.DisplayOrder - 1);
         Update(brother);
         ord.DisplayOrder = toupper ? (ord.DisplayOrder - 1) : (ord.DisplayOrder + 1);
         Update(ord);
     }
 }
Example #4
0
 protected void Update(TB_Permission per)
 {
     PermissionInstance.Update(p => p.id == per.id, update =>
     {
         update.Description  = per.Description;
         update.DisplayOrder = per.DisplayOrder;
         update.Image        = per.Image;
         update.IsDefault    = per.IsDefault;
         update.Name         = per.Name;
         update.Parent       = per.Parent;
         update.Url          = per.Url;
         update.Delete       = per.Delete;
     });
 }
Example #5
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="strId"></param>
        /// <param name="strParent"></param>
        protected void Edit(int newParent, TB_Permission obj)
        {
            // 修改
            var per = PermissionInstance.Find(p => p.id == obj.id);

            if (null == per)
            {
                // 无法进行更新
                ShowNotification("./permission_list.aspx", "Cannot edit permission: object not exist.", false);
                return;
            }
            else
            {
                // 查看是否更改了父级菜单
                if (newParent != per.Parent)
                {
                    // 更改了父级菜单
                    // 查找兄弟菜单并且显示顺序在本菜单之后的
                    var brothers = PermissionInstance.FindList(b => b.Parent == per.Parent && b.DisplayOrder > per.DisplayOrder);
                    foreach (var bro in brothers)
                    {
                        // 这些兄弟节点的显示顺序都减一
                        PermissionInstance.Update(u => u.id == bro.id, a =>
                        {
                            a.DisplayOrder = a.DisplayOrder - 1;
                        });
                    }
                    // 查找新兄弟菜单项
                    brothers = PermissionInstance.FindList(b => b.Parent == newParent);
                    // 菜单在新兄弟菜单项中显示在末尾
                    obj.Parent       = newParent;
                    obj.DisplayOrder = brothers.Count() + 1;
                }
                Update(obj);

                // 记录历史
                SaveHistory(new TB_AccountHistory()
                {
                    ActionId = ActionInstance.Find(f => f.Name.Equals("EditPermission")).id,
                    ObjectA  = "[id=" + per.id + "] " + (obj.Name.Equals(per.Name) ? obj.Name : ("[" + per.Name + "] to [" + obj.Name + "]"))
                });
                ShowNotification("./permission_list.aspx", "Success: You have changed the permission [" + per.Name + "].");
            }
        }