public override async Task <bool> UpdateAsync(Core.Entities.Users.User entity, bool useTransaction = false, int?commandTimeout = null)
        {
            var query = new Query(AttributeExtension.GetTableAttributeName <Core.Entities.Users.User>()).AsUpdate(new
            {
                entity.Name,
                entity.Email,
                entity.Active,
                entity.Deleted,
                entity.CreationTime
            }).Where("Id", "=", entity.Id);
            var sqlResult = GetSqlResult(query);

            try
            {
                await ExecuteAsync(sqlResult.Sql, sqlResult.NamedBindings);

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error($"UserRepository >> UpdateAsync Error: {ex.Message}");

                return(false);
            }
        }
        public PartialViewResult BlankListOption(string prefix)
        {
            ViewBag.Prefix = prefix;
            AttributeExtension attributeExtension = new AttributeExtension();

            return(PartialView("_ListOption", attributeExtension));
        }
示例#3
0
        public async Task <List <Core.Entities.IdentityResource.IdentityResource> > GetAllIdentityResourceList()
        {
            IDbSession session = DbSession;

            var query     = new Query(TableName).Select("*");
            var sqlResult = GetSqlResult(query);

            var result = (await session.Connection.QueryAsync <Core.Entities.IdentityResource.IdentityResource>(sqlResult.Sql, sqlResult.NamedBindings)).ToList();

            if (result.Any())
            {
                var identityResourceIds = result.Select(x => x.Id).ToArray();

                var claimQuery     = new Query(AttributeExtension.GetTableAttributeName <IdentityResourceClaim>()).Select("*").WhereIn("IdentityResourceId", identityResourceIds);
                var claimSqlResult = GetSqlResult(claimQuery);

                var propertyQuery     = new Query(AttributeExtension.GetTableAttributeName <IdentityResourceProperty>()).Select("*").WhereIn("IdentityResourceId", identityResourceIds);
                var propertySqlResult = GetSqlResult(propertyQuery);

                var multi = await session.Connection.QueryMultipleAsync($"{claimSqlResult.Sql};{propertySqlResult.Sql}", claimSqlResult.NamedBindings);

                var claims     = (await multi.ReadAsync <IdentityResourceClaim>()).ToList();
                var properties = (await multi.ReadAsync <IdentityResourceProperty>()).ToList();

                result.ForEach(x =>
                {
                    x.UserClaims = claims.Where(y => y.IdentityResourceId == x.Id).ToList();
                    x.Properties = properties.Where(y => y.IdentityResourceId == x.Id).ToList();
                });
            }

            return(result);
        }
        public async Task <List <Core.Entities.ApiResource.ApiResource> > GetApiResourcesByNameAsync(string[] apiResourceNames)
        {
            IDbSession session = DbSession;

            var resultQuery = new Query(TableName).Select("*");

            if (apiResourceNames != null && apiResourceNames.Any())
            {
                resultQuery = resultQuery.WhereIn("Name", apiResourceNames);
            }

            var resultSqlResult = GetSqlResult(resultQuery);

            try
            {
                List <Core.Entities.ApiResource.ApiResource> result = (await session.Connection.QueryAsync <Core.Entities.ApiResource.ApiResource>(resultSqlResult.Sql, resultSqlResult.NamedBindings)).ToList();
                if (result.Any())
                {
                    var apiResourceIds = result.Select(x => x.Id).Distinct().ToArray();

                    var secretQuery     = new Query(AttributeExtension.GetTableAttributeName <ApiResourceSecret>()).Select("*").WhereIn("ApiResourceId", apiResourceIds);
                    var secretSqlResult = GetSqlResult(secretQuery);
                    var secretResult    = await session.Connection.QueryAsync <ApiResourceSecret>(secretSqlResult.Sql,
                                                                                                  secretSqlResult.NamedBindings);

                    var scopeQuery     = new Query(AttributeExtension.GetTableAttributeName <ApiResourceScope>()).Select("*").WhereIn("ApiResourceId", apiResourceIds);
                    var scopeSqlResult = GetSqlResult(scopeQuery);
                    var scopeResult    =
                        await session.Connection.QueryAsync <ApiResourceScope>(scopeSqlResult.Sql,
                                                                               scopeSqlResult.NamedBindings);

                    var userClaimQuery     = new Query(AttributeExtension.GetTableAttributeName <ApiResourceClaim>()).Select("*").WhereIn("ApiResourceId", apiResourceIds);
                    var userClaimSqlResult = GetSqlResult(userClaimQuery);
                    var userClaimResult    =
                        await session.Connection.QueryAsync <ApiResourceClaim>(userClaimSqlResult.Sql,
                                                                               userClaimSqlResult.NamedBindings);

                    var propertyQuery     = new Query(AttributeExtension.GetTableAttributeName <ApiResourceProperty>()).Select("*").WhereIn("ApiResourceId", apiResourceIds);
                    var propertySqlResult = GetSqlResult(propertyQuery);
                    var propertyvResult   =
                        await session.Connection.QueryAsync <ApiResourceProperty>(propertySqlResult.Sql,
                                                                                  propertySqlResult.NamedBindings);


                    result.ForEach(x =>
                    {
                        x.Secrets    = secretResult.Where(y => y.ApiResourceId == x.Id).ToList();
                        x.Scopes     = scopeResult.Where(y => y.ApiResourceId == x.Id).ToList();
                        x.UserClaims = userClaimResult.Where(y => y.ApiResourceId == x.Id).ToList();
                        x.Properties = propertyvResult.Where(y => y.ApiResourceId == x.Id).ToList();
                    });
                }

                return(result);
            }
            finally
            {
                session.Dispose();
            }
        }
        public async Task <List <Core.Entities.ApiScope.ApiScope> > GetApiScopesByNameAsync(string[] scopeNames)
        {
            IDbSession session = DbSession;

            var query = new Query(TableName).Select("*");

            if (scopeNames != null && scopeNames.Any())
            {
                query = query.WhereIn("Name", scopeNames);
            }

            var sqlResult = GetSqlResult(query);

            var result = (await session.Connection.QueryAsync <Core.Entities.ApiScope.ApiScope>(sqlResult.Sql, sqlResult.NamedBindings)).ToList();

            if (result.Any())
            {
                var identityResourceIds = result.Select(x => x.Id).ToArray();

                var claimQuery     = new Query(AttributeExtension.GetTableAttributeName <ApiScopeClaim>()).Select("*").WhereIn("ScopeId", identityResourceIds);
                var claimSqlResult = GetSqlResult(claimQuery);

                var claims = await session.Connection.QueryAsync <ApiScopeClaim>(claimSqlResult.Sql, claimSqlResult.NamedBindings);

                result.ForEach(x =>
                {
                    x.UserClaims = claims.Where(y => y.ScopeId == x.Id).ToList();
                });
            }

            session.Dispose();

            return(result);
        }
        /// <summary>
        /// Returns rows count from specified table in an asynchronous manner.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual async Task <int> CountAsync <T>() where T : class
        {
            var tableName = AttributeExtension.TableNameAttributeValidate(typeof(T));
            var query     = $"SELECT COUNT(*) FROM {tableName}";
            var count     = await this.ExecuteScalarAsync <int>(query).ConfigureAwait(false);

            return(count);
        }
示例#7
0
 internal PropertySetterInfo(PropertyInfo propertyInfo, int propertyIndex, Action <TSource, object> func)
 {
     Name          = propertyInfo.Name;
     FieldName     = AttributeExtension.FieldNameAttributeValidate(propertyInfo);
     PropertyType  = propertyInfo.PropertyType;
     Setter        = func;
     PropertyIndex = propertyIndex;
 }
        /// <summary>
        /// Returns rows count from specified table.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual int Count <T>() where T : class
        {
            var tableName = AttributeExtension.TableNameAttributeValidate(typeof(T));
            var query     = $"SELECT COUNT(*) FROM {tableName}";
            var count     = this.ExecuteScalar <int>(query);

            return(count);
        }
        public async Task <bool> DeleteUserRoleByAsync(int userId, int roleId)
        {
            var query     = new Query(AttributeExtension.GetTableAttributeName <UserRoleMapping>()).Where("UserId", "=", userId).Where("RoleId", "=", roleId).AsDelete();
            var sqlResult = GetSqlResult(query);

            var result = await ExecuteAsync(sqlResult.Sql, sqlResult.NamedBindings);

            return(result > 0);
        }
        public async Task <bool> DeleteUserClaimByIdAsync(int id)
        {
            var query     = new Query(AttributeExtension.GetTableAttributeName <UserClaim>()).Where("Id", "=", id).AsDelete();
            var sqlResult = GetSqlResult(query);

            var deletedResult = await ExecuteAsync(sqlResult.Sql, sqlResult.NamedBindings);

            return(deletedResult > 0);
        }
示例#11
0
		public Join(AttributeExtension ext)
		{
			_tableName = (string)ext["TableName"];
			_alias     = (string)ext["Alias"];

			var col = ext.Attributes["On"];

			foreach (AttributeExtension ae in col)
				_joinOns.Add(new JoinOn(ae));
		}
示例#12
0
    private void SetField(string key, string value)
    {
        PropertyInfo propertyInfo = this.GetType().GetProperty(key, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

        if (propertyInfo == null)
        {
            return;
        }

        if (propertyInfo.PropertyType == typeof(int))
        {
            propertyInfo.SetValue(this, int.Parse(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(string))
        {
            propertyInfo.SetValue(this, value, null);
        }
        else if (propertyInfo.PropertyType == typeof(double))
        {
            propertyInfo.SetValue(this, double.Parse(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(bool))
        {
            propertyInfo.SetValue(this, bool.Parse(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(Attribute))
        {
            propertyInfo.SetValue(this, AttributeExtension.ToEnum(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(Target))
        {
            propertyInfo.SetValue(this, TargetExtension.ToEnum(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(Tribe))
        {
            propertyInfo.SetValue(this, TribeExtension.ToEnum(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(EnemyTribe))
        {
            propertyInfo.SetValue(this, EnemyTribeExtension.ToEnum(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(Job))
        {
            propertyInfo.SetValue(this, JobExtension.ToEnum(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(WeaponType))
        {
            propertyInfo.SetValue(this, WeaponTypeExtension.ToEnum(value), null);
        }
        else if (propertyInfo.PropertyType == typeof(SelectType))
        {
            propertyInfo.SetValue(this, SelectTypeExtension.ToEnum(value), null);
        }
        // 他の型にも対応させたいときには適当にここに。enumとかもどうにかなりそう。
    }
示例#13
0
        protected MarukoBaseRepository(IDataBaseUnitOfWork unitOfWork)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork is null");
            }

            UnitOfWork   = unitOfWork;
            _unitOfWork  = unitOfWork;
            _contextType = AttributeExtension.GetContextAttributeValue <TEntity>();
        }
示例#14
0
        public Join(AttributeExtension ext)
        {
            _tableName = (string)ext["TableName"];
            _alias     = (string)ext["Alias"];

            var col = ext.Attributes["On"];

            foreach (AttributeExtension ae in col)
            {
                _joinOns.Add(new JoinOn(ae));
            }
        }
示例#15
0
        public override async Task <bool> UpdateAsync(Core.Entities.IdentityResource.IdentityResource entity, bool useTransaction = false, int?commandTimeout = null)
        {
            IDbSession     session     = DbSession;
            IDbTransaction transaction = session.BeginTrans();

            try
            {
                var updatedResult = await session.Connection.UpdateAsync(entity, transaction);

                if (updatedResult)
                {
                    var deleteQuery     = new Query(AttributeExtension.GetTableAttributeName <IdentityResourceClaim>()).Where("IdentityResourceId", "=", entity.Id).AsDelete();
                    var deleteSqlResult = GetSqlResult(deleteQuery);

                    await session.Connection.ExecuteAsync(deleteSqlResult.Sql, deleteSqlResult.NamedBindings, transaction);

                    if (entity.UserClaims.Any())
                    {
                        var claimsColumns = new[]
                        {
                            "Type", "IdentityResourceId"
                        };
                        var insertClaimsQuery =
                            new Query(AttributeExtension.GetTableAttributeName <IdentityResourceClaim>()).AsInsert(
                                claimsColumns, entity.UserClaims.Select(x => new object[]
                        {
                            x.Type,
                            entity.Id
                        }));
                        var insertClaimsSqlResult = GetSqlResult(insertClaimsQuery);

                        await session.Connection.ExecuteAsync(insertClaimsSqlResult.Sql,
                                                              insertClaimsSqlResult.NamedBindings, transaction);
                    }
                }

                transaction.Commit();

                return(updatedResult);
            }
            catch (Exception ex)
            {
                transaction.Rollback();

                Log.Error($"IdentityResourceRepository >> UpdateAsync Error: {ex.Message}");

                return(false);
            }
            finally
            {
                session.Dispose();
            }
        }
        private static string GetPagedPath(int pageNumber, int pageSize, IUriService uri)
        {
            var absolutePath = uri.GetAbsolutePath();
            var modifiedUri  = QueryHelpers.AddQueryString(absolutePath,
                                                           AttributeExtension.GetAttributeFrom <PaginationQuery, FromQueryAttribute>(nameof(PaginationQuery.PageNumber)).Name,
                                                           pageNumber.ToString());

            modifiedUri = QueryHelpers.AddQueryString(modifiedUri,
                                                      AttributeExtension.GetAttributeFrom <PaginationQuery, FromQueryAttribute>(nameof(PaginationQuery.PageSize)).Name,
                                                      pageSize.ToString());
            return(modifiedUri);
        }
        private async Task CombineClient(Core.Entities.Clients.Client client, IDbSession session)
        {
            var scopeQuery = new Query(AttributeExtension.GetTableAttributeName <ClientScope>())
                             .Select("Scope").Where("ClientId", "=", client.Id);
            var scopeSqlResult = GetSqlResult(scopeQuery);

            var postLogoutRedirectUriQuery = new Query(AttributeExtension.GetTableAttributeName <ClientPostLogoutRedirectUri>())
                                             .Select("PostLogoutRedirectUri").Where("ClientId", "=", client.Id);
            var postLogoutRedirectUriSqlResult = GetSqlResult(postLogoutRedirectUriQuery);

            var clientIdPRestrictionQuery = new Query(AttributeExtension.GetTableAttributeName <ClientIdPRestriction>())
                                            .Select("Provider").Where("ClientId", "=", client.Id);
            var clientIdRestrictionResult = GetSqlResult(clientIdPRestrictionQuery);

            var redirectUrisQuery = new Query(AttributeExtension.GetTableAttributeName <ClientRedirectUri>())
                                    .Select("RedirectUri").Where("ClientId", "=", client.Id);
            var redirectUrisSqlResult = GetSqlResult(redirectUrisQuery);

            var corsOriginsQuery = new Query(AttributeExtension.GetTableAttributeName <ClientCorsOrigin>())
                                   .Select("Origin").Where("ClientId", "=", client.Id);
            var corsOriginsSqlResult = GetSqlResult(corsOriginsQuery);

            var grantTypesQuery = new Query(AttributeExtension.GetTableAttributeName <ClientGrantType>())
                                  .Select("GrantType").Where("ClientId", "=", client.Id);
            var grantTypesSqlResult = GetSqlResult(grantTypesQuery);

            var claimsQuery = new Query(AttributeExtension.GetTableAttributeName <ClientClaim>())
                              .Select("Id", "Type", "Value").Where("ClientId", "=", client.Id);
            var claimsSqlResult = GetSqlResult(claimsQuery);

            var secretsQuery = new Query(AttributeExtension.GetTableAttributeName <ClientSecret>())
                               .Select("Id", "Type", "Value").Where("ClientId", "=", client.Id);
            var secretsSqlResult = GetSqlResult(secretsQuery);

            var propertiesQuery = new Query(AttributeExtension.GetTableAttributeName <ClientProperty>())
                                  .Select("Id", "Key", "Value").Where("ClientId", "=", client.Id);
            var propertiesSqlResult = GetSqlResult(propertiesQuery);

            var multiQuery = await session.Connection.QueryMultipleAsync(
                $"{scopeSqlResult.Sql};{postLogoutRedirectUriSqlResult.Sql};{clientIdRestrictionResult.Sql};{redirectUrisSqlResult.Sql};{corsOriginsSqlResult.Sql};{grantTypesSqlResult.Sql};{claimsSqlResult.Sql};{secretsSqlResult.Sql};{propertiesSqlResult.Sql}",
                scopeSqlResult.NamedBindings);

            client.AllowedScopes                = (await multiQuery.ReadAsync <ClientScope>()).ToList();
            client.PostLogoutRedirectUris       = (await multiQuery.ReadAsync <ClientPostLogoutRedirectUri>()).ToList();
            client.IdentityProviderRestrictions = (await multiQuery.ReadAsync <ClientIdPRestriction>()).ToList();
            client.RedirectUris       = (await multiQuery.ReadAsync <ClientRedirectUri>()).ToList();
            client.AllowedCorsOrigins = (await multiQuery.ReadAsync <ClientCorsOrigin>()).ToList();
            client.AllowedGrantTypes  = (await multiQuery.ReadAsync <ClientGrantType>()).ToList();
            client.Claims             = multiQuery.Read <ClientClaim>().ToList();
            client.ClientSecrets      = multiQuery.Read <ClientSecret>().ToList();
            client.Properties         = multiQuery.Read <ClientProperty>().ToList();
        }
        public async Task <UserClaim> GetUserClaimByIdAsync(int id)
        {
            IDbSession session = DbSession;

            var query     = new Query(AttributeExtension.GetTableAttributeName <UserClaim>()).Select("*").Where("Id", "=", id);
            var sqlResult = GetSqlResult(query);

            var userClaim = await session.Connection.QueryFirstOrDefaultAsync <UserClaim>(sqlResult.Sql, sqlResult.NamedBindings);

            session.Dispose();

            return(userClaim);
        }
        public async Task <bool> IsUserRoleExistsAsync(int userId, int roleId)
        {
            IDbSession session = DbSession;

            var query     = new Query(AttributeExtension.GetTableAttributeName <UserRoleMapping>()).Select("*").Where("UserId", "=", userId).Where("RoleId", "=", roleId);
            var sqlResult = GetSqlResult(query);

            var result = (await session.Connection.QueryFirstOrDefaultAsync <UserRoleMapping>(sqlResult.Sql, sqlResult.NamedBindings)) != null;

            session.Dispose();

            return(result);
        }
示例#20
0
        public async Task <List <Core.Entities.Users.Role> > GetAllRolesAsync()
        {
            IDbSession session = DbSession;

            var query     = new Query(AttributeExtension.GetTableAttributeName <Core.Entities.Users.Role>()).Select("*");
            var sqlResult = GetSqlResult(query);

            var roles = (await session.Connection.QueryAsync <Core.Entities.Users.Role>(sqlResult.Sql, sqlResult.NamedBindings)).ToList();

            session.Dispose();

            return(roles);
        }
        public async Task <List <UserClaim> > GetUserClaimsByUserIdAsync(int userId)
        {
            IDbSession session = DbSession;

            var query     = new Query(AttributeExtension.GetTableAttributeName <UserClaim>()).Select("*").Where("UserId", "=", userId);
            var sqlResult = GetSqlResult(query);

            var userClaims = (await session.Connection.QueryAsync <UserClaim>(sqlResult.Sql, sqlResult.NamedBindings)).ToList();

            session.Dispose();

            return(userClaims);
        }
        public async Task <Core.Entities.Users.User> GetUserBySubjectId(string subjectId)
        {
            IDbSession session = DbSession;

            var query     = new Query(AttributeExtension.GetTableAttributeName <Core.Entities.Users.User>()).Select("*").Where("SubjectId", "=", subjectId);
            var sqlResult = GetSqlResult(query);

            var user = await session.Connection.QueryFirstOrDefaultAsync <Core.Entities.Users.User>(sqlResult.Sql, sqlResult.NamedBindings);

            session.Dispose();

            return(user);
        }
        public async Task <UserPassword> GetPasswordByUserIdAsync(int userId)
        {
            IDbSession session = DbSession;

            var query     = new Query(AttributeExtension.GetTableAttributeName <UserPassword>()).Select("*").Where("UserId", "=", userId).OrderByDesc("CreationTime");
            var sqlResult = GetSqlResult(query);

            var userPassword = await session.Connection.QueryFirstOrDefaultAsync <UserPassword>(sqlResult.Sql, sqlResult.NamedBindings);

            session.Dispose();

            return(userPassword);
        }
        public async Task <PagedLocalStringResourceDto> GetPagedAsync(int languageId, string search, int page, int pageSize)
        {
            var result = new PagedLocalStringResourceDto();

            IDbSession session = DbSession;

            try
            {
                var languageQuery     = new Query(AttributeExtension.GetTableAttributeName <Language>()).Select("Id", "Name").Where("Id", "=", languageId);
                var languageSqlResult = GetSqlResult(languageQuery);
                var language          = await session.Connection.QueryFirstOrDefaultAsync <Language>(languageSqlResult.Sql, languageSqlResult.NamedBindings);

                if (language != null)
                {
                    result.LanguageId   = language.Id;
                    result.LanguageName = language.Name;

                    var totalCountQuery = new Query(TableName).AsCount();
                    var resultQuery     = new Query(TableName).Select("*");

                    if (languageId > 0)
                    {
                        totalCountQuery = totalCountQuery.Where("LanguageId", "=", languageId);
                        resultQuery     = resultQuery.Where("LanguageId", "=", languageId);
                    }

                    if (!string.IsNullOrEmpty(search))
                    {
                        totalCountQuery = totalCountQuery.WhereContains("ResourceName", search).OrWhereContains("ResourceValue", search);
                        resultQuery     = resultQuery.WhereContains("ResourceName", search).OrWhereContains("ResourceValue", search);
                    }

                    var totalCountSqlResult = GetSqlResult(totalCountQuery);

                    resultQuery = resultQuery.OrderByDesc("Id").Offset((page - 1) * pageSize).Limit(pageSize);
                    var clientSecretSqlResult = GetSqlResult(resultQuery);

                    result.TotalCount = await session.Connection.QueryFirstOrDefaultAsync <int>(totalCountSqlResult.Sql, totalCountSqlResult.NamedBindings);

                    result.DataPagedList = (await session.Connection.QueryAsync <LocalStringResourceForPage>(clientSecretSqlResult.Sql, clientSecretSqlResult.NamedBindings)).ToList();

                    result.PageSize = pageSize;
                }

                return(result);
            }
            finally
            {
                session.Dispose();
            }
        }
        public async Task <int> InsertUserClaimAsync(UserClaim userClaim)
        {
            var query = new Query(AttributeExtension.GetTableAttributeName <UserClaim>()).AsInsert(new
            {
                userClaim.UserId,
                userClaim.ClaimType,
                userClaim.ClaimValue
            });
            var sqlResult = GetSqlResult(query);

            var insertedResult = await ExecuteAsync(sqlResult.Sql, sqlResult.NamedBindings);

            return(insertedResult);
        }
示例#26
0
 static void FillRelationIndex(string[] index, AttributeExtension attributeExtension, string indexName)
 {
     if (index.Any())
     {
         var collection = new AttributeExtensionCollection();
         foreach (var s in index)
         {
             var ae = new AttributeExtension();
             ae.Values.Add(TypeExtension.AttrName.Name, s);
             collection.Add(ae);
         }
         attributeExtension.Attributes.Add(indexName, collection);
     }
 }
示例#27
0
        public async Task <PagedClientSecretDto> GetPagedAsync(int clientId, int page, int pageSize)
        {
            var clientSecret = new PagedClientSecretDto();

            if (clientId <= 0)
            {
                return(clientSecret);
            }

            IDbSession session = DbSession;

            var clientQuery     = new Query(AttributeExtension.GetTableAttributeName <Core.Entities.Clients.Client>()).Select("Id", "ClientName").Where("Id", "=", clientId);
            var clientSqlResult = GetSqlResult(clientQuery);
            var client          = await session.Connection.QueryFirstOrDefaultAsync <Core.Entities.Clients.Client>(clientSqlResult.Sql, clientSqlResult.NamedBindings);

            try
            {
                if (client != null)
                {
                    clientSecret.ClientId   = client.Id;
                    clientSecret.ClientName = client.ClientName;

                    var totalCountQuery = new Query(TableName).AsCount();
                    var resultQuery     = new Query(TableName).Select("*");

                    totalCountQuery = totalCountQuery.Where("ClientId", "=", clientId);
                    resultQuery     = resultQuery.Where("ClientId", "=", clientId);

                    var totalCountSqlResult = GetSqlResult(totalCountQuery);

                    resultQuery = resultQuery.OrderByDesc("Id").Offset((page - 1) * pageSize).Limit(pageSize);
                    var clientSecretSqlResult = GetSqlResult(resultQuery);

                    clientSecret.TotalCount = await session.Connection.QueryFirstOrDefaultAsync <int>(totalCountSqlResult.Sql, totalCountSqlResult.NamedBindings);

                    clientSecret.DataPagedList = (await session.Connection.QueryAsync <ClientSecretDetailForPage>(clientSecretSqlResult.Sql, clientSecretSqlResult.NamedBindings)).ToList();

                    clientSecret.PageSize = pageSize;

                    return(clientSecret);
                }
            }
            finally
            {
                session.Dispose();
            }

            return(clientSecret);
        }
        public async Task <int> InsertUserPasswordAsync(UserPassword userPassword)
        {
            var query = new Query(AttributeExtension.GetTableAttributeName <UserPassword>()).AsInsert(new
            {
                userPassword.UserId,
                userPassword.PasswordSalt,
                userPassword.Password,
                userPassword.CreationTime
            });
            var sqlResult = GetSqlResult(query);

            var insertedResult = await ExecuteAsync(sqlResult.Sql, sqlResult.NamedBindings);

            return(insertedResult);
        }
示例#29
0
        /// <summary>
        /// Returns rows count from specified table.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static int Count <T>(this IDatabaseConnector connector) where T : class
        {
            var con = connector as DatabaseConnectorBase;

            if (con == null)
            {
                throw new InvalidCastException($"{connector.GetType().FullName} cannot be use with this extension (expected to get instance of {typeof(DatabaseConnectorBase).FullName}");
            }
            var tableName     = AttributeExtension.TableNameAttributeValidate(typeof(T));
            var query         = $"SELECT COUNT(*) FROM {tableName}";
            var count         = con.ExecuteScalar(query);
            var countAsString = count.ToString();

            return(int.Parse(countAsString));
        }
        public async Task <List <string> > GetClientCorsOriginList(string origin)
        {
            IDbSession session = DbSession;

            var query = new Query($"{TableName} as t").Join($"{AttributeExtension.GetTableAttributeName<ClientCorsOrigin>()} as t1", "t.Id", "t1.ClientId")
                        .Select("t1.Origin").WhereContains("t1.Origin", origin);

            var sqlResult = GetSqlResult(query);

            var origins = (await session.Connection.QueryAsync <string>(sqlResult.Sql, sqlResult.NamedBindings)).ToList();

            session.Dispose();

            return(origins);
        }
        public async Task <int> UpdateUserPasswordAsync(UserPassword userPassword)
        {
            var query = new Query(AttributeExtension.GetTableAttributeName <UserPassword>()).AsUpdate(new
            {
                userPassword.UserId,
                userPassword.PasswordSalt,
                userPassword.Password,
                userPassword.CreationTime
            }).Where("Id", "=", userPassword.Id);
            var sqlResult = GetSqlResult(query);

            var updatedResult = await ExecuteAsync(sqlResult.Sql, sqlResult.NamedBindings);

            return(updatedResult);
        }
示例#32
0
		public JoinOn(AttributeExtension ext)
		{
			_field      = (string)ext["Field"];
			_otherField = (string)ext["OtherField"];
			_expression = (string)ext["Expression"];
		}