示例#1
0
        /// <summary>从给定的字段集合中返回不允许看的字段集合</summary>
        /// <param name="fieldNames">给定的字段集合</param>
        /// <returns></returns>
        public List <String> GetRejectFieldNames(ICollection <String> fieldNames)
        {
            //当前请求所在菜单及其权限
            Permission current = GetCurrentMenu();

            if (current == null || current.RoleMenu == null || String.IsNullOrEmpty(current.RoleMenu.FieldNames))
            {
                return(null);
            }
            RoleMenu rm = current.RoleMenu;

            String[] ss = rm.FieldNames.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (ss.Length == 0)
            {
                return(null);
            }
            //字段权限类型:1允许0拒绝
            Boolean isAllow = rm.IsAllow;
            //需要置空的字段集合
            List <String> rejectFieldNames = new List <String>();

            //如果是仅仅允许看某些个字段
            if (isAllow)
            {
                foreach (String item in fieldNames)
                {
                    if (!ss.Contains(item))
                    {
                        rejectFieldNames.Add(item);
                    }
                }
            }
            else
            {
                foreach (String s in ss)
                {
                    if (fieldNames.Contains(s))
                    {
                        rejectFieldNames.Add(s);
                    }
                }
            }
            return(rejectFieldNames);
        }
示例#2
0
        /// <summary>插入菜单权限</summary>
        protected int InsertMenuPermission()
        {
            var result = 0;

            if (!String.IsNullOrEmpty(MenuPermission))
            {
                List <MenuPermissionDto> mps = JsonConvert.DeserializeObject <List <MenuPermissionDto> >(MenuPermission);
                if (mps != null && mps.Count > 0)
                {
                    foreach (MenuPermissionDto item in mps)
                    {
                        RoleMenu rm = new RoleMenu();
                        rm.RoleID     = ID;
                        rm.MenuID     = item.ID;
                        rm.IsAllow    = item.IsAllow;
                        rm.FieldNames = item.FieldNames;
                        rm.Insert();
                        if (item.MenuButtons != null && item.MenuButtons.Count > 0)
                        {
                            EntityList <RoleMenuButton> list = new EntityList <RoleMenuButton>();
                            foreach (var mb in item.MenuButtons)
                            {
                                RoleMenuButton rmb = new RoleMenuButton();
                                rmb.RoleID       = ID;
                                rmb.MenuID       = item.ID;
                                rmb.ButtonID     = mb.ButtonID;
                                rmb.MenuButtonID = mb.MenuButtonID;
                                list.Add(rmb);
                            }
                            result += list.Insert();
                        }
                    }
                }
            }
            return(result);
        }