Beispiel #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;
            }
        }
Beispiel #2
0
 public static SysRelation_CE ToCE(SysRelationEntity item)
 {
     SysRelation_CE target = new SysRelation_CE();
     target.ID=item.ID;
     target.RoleNum=item.RoleNum;
     target.ResNum=item.ResNum;
     target.ResType=item.ResType;
     return target;
 }
Beispiel #3
0
 /// <summary>
 /// 获得所有的已经分配的权限关系列表
 /// </summary>
 /// <returns></returns>
 private List<SysRelationEntity> GetList()
 {
     List<SysRelationEntity> list = CacheHelper.Get(CacheKey.JOOSHOW_ALLOTPOWER_CACHE) as List<SysRelationEntity>;
     if (!list.IsNullOrEmpty())
     {
         return list;
     }
     SysRelationEntity entity = new SysRelationEntity();
     entity.IncludeAll();
     list = this.SysRelation.GetList(entity);
     if (!list.IsNullOrEmpty())
     {
         CacheHelper.Insert(CacheKey.JOOSHOW_ALLOTPOWER_CACHE, list, null, DateTime.Now.AddDays(1));
     }
     return list;
 }