예제 #1
0
 public void SaveRoleAuth(string roleId, string ids)
 {
     Sqldb.Deleteable <sys_role_authorize>().Where(s => s.role_id == SqlFunc.ToInt64(roleId)).ExecuteCommand();
     if (!string.IsNullOrEmpty(ids))
     {
         var list    = new List <sys_role_authorize>();
         var menuIds = ids.ToObject <List <ZtreeDto> >();
         foreach (var mid in menuIds)
         {
             mid.pId = mid.pId ?? "0";
             var model = new sys_role_authorize();
             model.id            = IdWorkerHelper.NewId();
             model.role_id       = roleId.ToInt64();
             model.menu_id       = mid.id.ToInt64();
             model.menu_pid      = mid.pId.ToInt64();
             model.create_time   = DateTime.Now;
             model.create_person = UserCookie.AccountName;
             list.Add(model);
         }
         if (list.Any())
         {
             Sqldb.Insertable(list).ExecuteCommand();
         }
     }
 }
예제 #2
0
        /// <summary>
        /// 保存权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="ids"></param>
        public void SavePermissions(long roleId, string ids, LoginUserDto UserCookie)
        {
            Sqldb.Delete <sys_role_authorize>().Where(s => s.role_id == roleId).ExecuteAffrows();

            if (!string.IsNullOrEmpty(ids))
            {
                var list = new List <sys_role_authorize>();

                //var menuIds = ids.Split(',');
                var menuIds = ids.ToObject <List <ZtreeSelInt64Dto> >();
                var nowTime = DateTime.Now;
                foreach (var mid in menuIds)
                {
                    var model = new sys_role_authorize();
                    model.id            = IdHelper.NextId();
                    model.role_id       = roleId;
                    model.menu_id       = mid.id;
                    model.menu_pid      = mid.pId;
                    model.create_time   = nowTime;
                    model.create_person = UserCookie.LoginName;
                    list.Add(model);
                }


                if (list.Any())
                {
                    Sqldb.Insert(list).ExecuteAffrows();
                }
            }

            //移除全部权限
            PermissionCache.RemoveAllPermission(roleId);
        }