Пример #1
0
        public void Insert(AccessTokenInfo accessTokenInfo)
        {
            var token = TranslateUtils.EncryptStringBySecretKey(StringUtils.Guid());

            var sqlString = $@"INSERT INTO {TableName}
           ({nameof(AccessTokenInfo.Title)}, 
            {nameof(AccessTokenInfo.Token)},
            {nameof(AccessTokenInfo.Scopes)},
            {nameof(AccessTokenInfo.RateLimit)},
            {nameof(AccessTokenInfo.AddDate)},
            {nameof(AccessTokenInfo.UpdatedDate)})
     VALUES
           (@{nameof(AccessTokenInfo.Title)}, 
            @{nameof(AccessTokenInfo.Token)},
            @{nameof(AccessTokenInfo.Scopes)},
            @{nameof(AccessTokenInfo.RateLimit)},
            @{nameof(AccessTokenInfo.AddDate)},
            @{nameof(AccessTokenInfo.UpdatedDate)})";

            IDataParameter[] parameters =
            {
                GetParameter(nameof(accessTokenInfo.Title),       DataType.VarChar,                         200, accessTokenInfo.Title),
                GetParameter(nameof(accessTokenInfo.Token),       DataType.VarChar,                         200, token),
                GetParameter(nameof(accessTokenInfo.Scopes),      DataType.VarChar,                         200, accessTokenInfo.Scopes),
                GetParameter(nameof(accessTokenInfo.RateLimit),   DataType.Integer,  accessTokenInfo.RateLimit),
                GetParameter(nameof(accessTokenInfo.AddDate),     DataType.DateTime, DateTime.Now),
                GetParameter(nameof(accessTokenInfo.UpdatedDate), DataType.DateTime, DateTime.Now)
            };

            ExecuteNonQuery(sqlString, parameters);

            AccessTokenManager.ClearCache();
        }
Пример #2
0
        public void Delete(int id)
        {
            if (id <= 0)
            {
                return;
            }

            var sqlString = $"DELETE FROM {TableName} WHERE {nameof(AccessTokenInfo.Id)} = {id}";

            ExecuteNonQuery(sqlString);

            AccessTokenManager.ClearCache();
        }
Пример #3
0
        public string Regenerate(int id)
        {
            var token = TranslateUtils.EncryptStringBySecretKey(StringUtils.Guid());

            var sqlString = $@"UPDATE {TableName} SET
                {nameof(AccessTokenInfo.Token)} = @{nameof(AccessTokenInfo.Token)}, 
                {nameof(AccessTokenInfo.UpdatedDate)} = @{nameof(AccessTokenInfo.UpdatedDate)}
            WHERE {nameof(AccessTokenInfo.Id)} = @{nameof(AccessTokenInfo.Id)}";

            IDataParameter[] parameters =
            {
                GetParameter(nameof(AccessTokenInfo.Token),       DataType.VarChar,            200, token),
                GetParameter(nameof(AccessTokenInfo.UpdatedDate), DataType.DateTime, DateTime.Now),
                GetParameter(nameof(AccessTokenInfo.Id),          DataType.Integer,  id)
            };

            ExecuteNonQuery(sqlString, parameters);

            AccessTokenManager.ClearCache();

            return(token);
        }
Пример #4
0
        public void Update(AccessTokenInfo accessTokenInfo)
        {
            var sqlString = $@"UPDATE {TableName} SET
                {nameof(AccessTokenInfo.Title)} = @{nameof(AccessTokenInfo.Title)}, 
                {nameof(AccessTokenInfo.Scopes)} = @{nameof(AccessTokenInfo.Scopes)},
                {nameof(AccessTokenInfo.RateLimit)} = @{nameof(AccessTokenInfo.RateLimit)},
                {nameof(AccessTokenInfo.UpdatedDate)} = @{nameof(AccessTokenInfo.UpdatedDate)}
            WHERE {nameof(AccessTokenInfo.Id)} = @{nameof(AccessTokenInfo.Id)}";

            IDataParameter[] parameters =
            {
                GetParameter(nameof(accessTokenInfo.Title),       DataType.VarChar,            200, accessTokenInfo.Title),
                GetParameter(nameof(accessTokenInfo.Scopes),      DataType.VarChar,            200, accessTokenInfo.Scopes),
                GetParameter(nameof(accessTokenInfo.RateLimit),   DataType.VarChar,            200, accessTokenInfo.RateLimit),
                GetParameter(nameof(accessTokenInfo.UpdatedDate), DataType.DateTime, DateTime.Now),
                GetParameter(nameof(accessTokenInfo.Id),          DataType.Integer,  accessTokenInfo.Id)
            };

            ExecuteNonQuery(sqlString, parameters);

            AccessTokenManager.ClearCache();
        }