Пример #1
0
        bool HasPermission(string UserId, string Key, PermissionType Type = PermissionType.Menu)
        {
            log.Info("ProtalHasPermission", UserId, Key, Type);
            if (UserId.IsEmpty())
            {
                return(false);
            }
            if (Key.IsEmpty())
            {
                return(true);
            }
            if (UserId.ToInt() < 0)
            {
                return(true);
            }
            switch (Type)
            {
            case PermissionType.Menu:
            {
                ICache wc = new WebCache();
                return(wc.Simple($"Permission_{Type.ToString()}_{UserId}",
                                 () => _db.ExecuteTable($@"SELECT A.MENUID FROM USERMODULE A,MENU B where A.MENUID = B.ID
                                                and exists(select 1 from USER_ROLE A1, ROLE_MENU B1,USERMODULE C1 where A1.USERID= '{UserId}'
                                                and A1.ROLEID = B1.ROLEID and B1.MENUID=C1.MENUID and C1.MENUID = A.MENUID )")
                                 .ToList <string>().ToArray())
                       .Contains(Type.ToString() + Key));
            }

            default:
            {
                throw new Exception("未知的权限类型");
            }
            }
        }
Пример #2
0
 /// <summary>
 /// 在表里必须是唯一的
 /// </summary>
 /// <param name="p"></param>
 /// <param name="ErrorModel"></param>
 public void IsUnique(Expression <Func <TEntity, string> > p, int limit = 0, string ErrorModel = "[{0}]表中字段[{1}]的值[{2}]已存在")
 {
     if (p.Body is MemberExpression)
     {
         MemberExpression me   = p.Body as MemberExpression;
         PropertyInfo     prop = me.Member as PropertyInfo;
         string           str  = prop.GetValue(_entity)?.ToString().Trim();
         //if (_entity.HasAllPrimaryKey() && _dbHelper.Select(_entity) != null)
         //{
         //    TEntity rest = _dbHelper.Select(_entity);
         //    if (rest != null)
         //    {
         //        if (prop.GetValue(rest)?.ToString().Trim() == str)
         //        {
         //            limit++;
         //        }
         //    }
         //}
         string         sql = $"select {_entity.GetPrimaryKey().Select(s => s.Name).ToArray().SuperJoin(",")} from {_entity.GetTableName()} where {me.Member.Name}='{str}'";
         List <TEntity> res = _dbHelper.ExecuteTable(sql).ToList <TEntity>();
         if (res.Where(a => !a.EqualWithPrimary(_entity)).Count() > limit)
         {
             SetError(string.Format(ErrorModel, _entity.GetComments(), _entity.GetFieldName(p), str));
         }
     }
     else
     {
         throw new Exception("此校验只对字段属性生效");
     }
 }
Пример #3
0
 /// <summary>
 /// 在表里必须是唯一的
 /// </summary>
 /// <param name="p"></param>
 /// <param name="ErrorModel"></param>
 public void IsUnique(Expression <Func <TEntity, string> > p, string ErrorModel = "[{0}]表中字段[{1}]的值[{2}]已存在")
 {
     if (p.Body is MemberExpression)
     {
         MemberExpression me   = p.Body as MemberExpression;
         PropertyInfo     prop = me.Member as PropertyInfo;
         FieldAttribute   fa   = prop.GetAttribute <FieldAttribute>();
         string           str  = prop.GetValue(_entity)?.ToString().Trim();
         string           sql  = $"select 1 from {_entity.GetTableName()} where {me.Member.Name}='{str}'";
         if (_dbHelper.ExecuteTable(sql).Rows.Count != 0)
         {
             SetError(string.Format(ErrorModel, _entity.GetComments(), fa == null ? me.Member.Name : fa.Fieldname, str));
         }
     }
     else
     {
         throw new Exception("此校验只对字段属性生效");
     }
 }