예제 #1
0
        /// <summary>
        /// 给某个角色分配权限
        /// </summary>
        /// <param name="roleNum"></param>
        /// <param name="resItems"></param>
        /// <returns></returns>
        public int AllotPower(string roleNum, List<string> resItems)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                int line = 0;
                if (!resItems.IsNullOrEmpty())
                {
                    SysRelationEntity entity = new SysRelationEntity();
                    entity.Where(a => a.RoleNum == roleNum);
                    line = this.SysRelation.Delete(entity);

                    SysResourceProvider provider = new SysResourceProvider();

                    List<SysRelationEntity> list = new List<SysRelationEntity>();
                    foreach (string resNum in resItems)
                    {
                        SysResourceEntity resource = provider.GetResource(resNum);
                        short ResType = resource != null ? resource.ResType : (short)EResourceType.Page;
                        entity = new SysRelationEntity() { RoleNum = roleNum, ResNum = resNum, ResType = ResType };
                        entity.IncludeAll();
                        list.Add(entity);
                    }
                    line += this.SysRelation.Add(list);
                }
                ts.Complete();
                if (line > 0)
                {
                    CacheHelper.Remove(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, roleNum));
                    CacheHelper.Remove(CacheKey.JOOSHOW_ALLOTPOWER_CACHE);
                }
                return line;
            }
        }
예제 #2
0
        /// <summary>
        /// 给某个角色分配权限
        /// </summary>
        /// <param name="roleNum"></param>
        /// <param name="resItems"></param>
        /// <returns></returns>
        public int AllotPower(string roleNum, List <string> resItems)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                int line = 0;
                if (!resItems.IsNullOrEmpty())
                {
                    List <string>            listInfo   = new List <string>();
                    List <SysResourceEntity> ListSource = new SysResourceProvider(this.CompanyID).GetList();
                    ListSource = ListSource.IsNull() ? new List <SysResourceEntity>() : ListSource;

                    resItems.ForEach(a =>
                    {
                        SysResourceEntity res = ListSource.FirstOrDefault(b => b.ResNum == a);
                        if (res != null && res.ParentNum.IsNotEmpty())
                        {
                            SysResourceEntity parent = ListSource.FirstOrDefault(b => b.ResNum == res.ParentNum);
                            listInfo.Add(parent.ResNum);
                        }
                        listInfo.Add(a);
                    });

                    SysRelationEntity entity = new SysRelationEntity();
                    entity.Where(a => a.RoleNum == roleNum);
                    line = this.SysRelation.Delete(entity);

                    SysResourceProvider provider = new SysResourceProvider(this.CompanyID);

                    List <SysRelationEntity> list = new List <SysRelationEntity>();
                    foreach (string resNum in listInfo)
                    {
                        SysResourceEntity resource = provider.GetResource(resNum);
                        short             ResType  = resource != null ? resource.ResType : (short)EResourceType.Page;
                        entity = new SysRelationEntity()
                        {
                            RoleNum = roleNum, ResNum = resNum, ResType = ResType, CompanyID = this.CompanyID
                        };
                        entity.SnNum = entity.SnNum.IsEmpty() ? ConvertHelper.NewGuid() : entity.SnNum;
                        entity.IncludeAll();
                        list.Add(entity);
                    }
                    line += this.SysRelation.Add(list);
                }
                ts.Complete();
                if (line > 0)
                {
                    CacheHelper.Remove(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, roleNum));
                    CacheHelper.Remove(CacheKey.JOOSHOW_ALLOTPOWER_CACHE);
                }
                return(line);
            }
        }
예제 #3
0
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <returns></returns>
        public ActionResult AddMenu()
        {
            string resNum = WebUtil.GetQueryStringValue<string>("resNum");

            if (resNum.IsEmpty())
            {
                ViewBag.RoleList = BaseHelper.GetParentMenu(string.Empty);
                SysResourceEntity entity = new SysResourceEntity();
                ViewBag.Menu = entity;
                ViewBag.ResourceType = EnumHelper.GetOptions<EResourceType>(EResourceType.Page,"请选择菜单类型");
                return View();
            }
            else
            {
                SysResourceProvider provider = new SysResourceProvider();
                SysResourceEntity entity = provider.GetResource(resNum);
                entity = entity == null ? new SysResourceEntity() : entity;
                ViewBag.RoleList = BaseHelper.GetParentMenu(entity.ParentNum);
                ViewBag.Menu = entity;
                ViewBag.ResourceType = EnumHelper.GetOptions<EResourceType>(entity.ResType, "请选择菜单类型");
                return View();
            }
        }
예제 #4
0
        /// <summary>
        /// 给某个角色分配权限
        /// </summary>
        /// <param name="roleNum"></param>
        /// <param name="resItems"></param>
        /// <returns></returns>
        public int AllotPower(string roleNum, List <string> resItems)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                int line = 0;
                if (!resItems.IsNullOrEmpty())
                {
                    SysRelationEntity entity = new SysRelationEntity();
                    entity.Where(a => a.RoleNum == roleNum);
                    line = this.SysRelation.Delete(entity);

                    SysResourceProvider provider = new SysResourceProvider();

                    List <SysRelationEntity> list = new List <SysRelationEntity>();
                    foreach (string resNum in resItems)
                    {
                        SysResourceEntity resource = provider.GetResource(resNum);
                        short             ResType  = resource != null ? resource.ResType : (short)EResourceType.Page;
                        entity = new SysRelationEntity()
                        {
                            RoleNum = roleNum, ResNum = resNum, ResType = ResType
                        };
                        entity.IncludeAll();
                        list.Add(entity);
                    }
                    line += this.SysRelation.Add(list);
                }
                ts.Complete();
                if (line > 0)
                {
                    CacheHelper.Remove(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, roleNum));
                    CacheHelper.Remove(CacheKey.JOOSHOW_ALLOTPOWER_CACHE);
                }
                return(line);
            }
        }