Esempio n. 1
0
        /// <summary>	Gets by identifier statement. </summary>
        /// <param name="type">	The type. </param>
        /// <returns>	The by identifier statement. </returns>
        public virtual string GetByKeyStatement(Type type)
        {
            var key = SqlCache.TypeKeyPropertiesCache(type).Single();

            return
                ($"SELECT {RenderPropertyList(SqlCache.TypePropertiesChache(type).ToArray())} FROM {RenderTableName(type)} WHERE {RenderPropertyName(key)} = {RenderParameterProperty(key)}");
        }
Esempio n. 2
0
        /// <summary>	Gets by filter statement. </summary>
        /// <param name="type">			    The type. </param>
        /// <param name="filterProperties">	The filter properties. </param>
        /// <param name="selectFields">	    The select fields. </param>
        /// <returns>	The by filter statement. </returns>
        public virtual string GetByFilterStatement(Type type, string[] filterProperties, string[] selectFields)
        {
            var fProps = SqlCache.TypePropertiesChache(type).Where(pi => filterProperties.Contains(pi.Name)).ToArray();
            var sb     = new StringBuilder();

            for (var i = 0; i < filterProperties.Length; i++)
            {
                if (i > 0)
                {
                    sb.Append(" AND ");
                }
                sb.Append($"{RenderPropertyName(fProps[i])} = {RenderParameterProperty(fProps[i])}");
            }

            var filterSql = sb.ToString();

            if (selectFields == null || selectFields.Length < 1)
            {
                return
                    ($"SELECT {RenderPropertyList(SqlCache.TypePropertiesChache(type).ToArray())} FROM {RenderTableName(type)} WHERE {filterSql}");
            }

            var sProps = SqlCache.TypePropertiesChache(type).Where(pi => selectFields.Contains(pi.Name)).ToArray();

            return
                ($"SELECT {RenderPropertyList(sProps)} FROM {RenderTableName(type)} WHERE {filterSql}");
        }
Esempio n. 3
0
        /// <summary>	Gets the scope identifiers in this collection. </summary>
        /// <param name="ids">	The identifiers. </param>
        /// <returns>
        ///     An enumerator that allows foreach to be used to process the scope identifiers in this
        ///     collection.
        /// </returns>
        public override IEnumerable <IdentityResourceScopeEntity> GetByScopeIds(int[] ids)
        {
            var command =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(IdentityResourceScopeEntity)).ToArray())} FROM {TableName} WHERE {nameof(IdentityResourceScopeEntity.ScopeId)} IN @Ids";

            return(UnitOfWork.Connection.Query <IdentityResourceScopeEntity>(command, new { Ids = ids },
                                                                             UnitOfWork.Transaction));
        }
Esempio n. 4
0
        /// <summary>	Gets the names in this collection. </summary>
        /// <param name="names">	The names. </param>
        /// <returns>
        ///     An enumerator that allows foreach to be used to process the names in this collection.
        /// </returns>
        public override IEnumerable <ScopeEntity> GetByNames(string[] names)
        {
            var command =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(ScopeEntity)).ToArray())} FROM {TableName} WHERE \"{nameof(ScopeEntity.Name)}\" = ANY(@Names)";

            return(UnitOfWork.Connection.Query <ScopeEntity>(command, new { Names = names },
                                                             UnitOfWork.Transaction));
        }
        /// <summary>	Finds the identifiers in this collection. </summary>
        /// <param name="roleIds">	List of identifiers for the roles. </param>
        /// <returns>
        ///     An enumerator that allows foreach to be used to process the identifiers in this collection.
        /// </returns>
        public override IEnumerable <IdentityRoleEntity> FindByIds(IEnumerable <int> roleIds)
        {
            var command =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(IdentityRoleEntity)).ToArray())} FROM {TableName} WHERE \"{nameof(IdentityUserEntity.Id)}\" = ANY(@Ids)";

            return(UnitOfWork.Connection.Query <IdentityRoleEntity>(command, new { Ids = roleIds.ToArray() },
                                                                    UnitOfWork.Transaction));
        }
        /// <summary>	Gets validation valid. </summary>
        /// <param name="validSince">	The valid since Date/Time. </param>
        /// <returns>	The validation valid. </returns>
        public override IList <SigningCredentialEntity> GetValidationValid(DateTime validSince)
        {
            var command =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(SigningCredentialEntity)).ToArray())} FROM {TableName} WHERE {nameof(SigningCredentialEntity.Issued)} > @validSince";

            return(UnitOfWork.Connection.Query <SigningCredentialEntity>(command, new { ValidSince = validSince },
                                                                         UnitOfWork.Transaction).ToList());
        }
        /// <summary>	Gets the latest. </summary>
        /// <returns>	The latest. </returns>
        public override SigningCredentialEntity GetLatest()
        {
            var command =
                $"SELECT TOP 1 {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(SigningCredentialEntity)).ToArray())} FROM {TableName} ORDER BY {nameof(SigningCredentialEntity.Issued)} DESC";

            return(UnitOfWork.Connection.QuerySingleOrDefault <SigningCredentialEntity>(command, null,
                                                                                        UnitOfWork.Transaction));
        }
        /// <summary>	Gets the name compounts in this collection. </summary>
        /// <param name="name">	The name. </param>
        /// <returns>
        ///     An enumerator that allows foreach to be used to process the name compounts in this collection.
        /// </returns>
        public override CompoundApiResource GetByNameCompount(string name)
        {
            var command =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(ApiResourceEntity)).ToArray())} FROM {TableName} AS aRes" +
                $" LEFT JOIN {UnitOfWork.GetRepository<IApiResourceScopeRepository>().TableName} AS aScope" +
                $" ON aRes.{nameof(ApiResourceEntity.Id)} = aScope.{nameof(ApiResourceScopeEntity.ApiResourceId)}" +
                $" LEFT JOIN {UnitOfWork.GetRepository<IApiResourceClaimRepository>().TableName} AS aClaim" +
                $" ON aRes.{nameof(ApiResourceEntity.Id)} = aClaim.{nameof(ApiResourceClaimEntity.ApiResourceId)}" +
                $" LEFT JOIN {UnitOfWork.GetRepository<IScopeRepository>().TableName} AS scope" +
                $" ON aScope.{nameof(ApiResourceScopeEntity.ScopeId)} = scope.{nameof(ScopeEntity.Id)}" +
                $" WHERE aRes.{nameof(ApiResourceEntity.Name)} = @ResName";
            var lookup = new Dictionary <int, CompoundApiResource>();

            UnitOfWork.Connection
            .Query <ApiResourceEntity, ApiResourceScopeEntity, ApiResourceClaimEntity, ScopeEntity,
                    CompoundApiResource>(command,
                                         (entity, apiScope, apiClaim, scope) =>
            {
                // make sure the pk exists
                if (entity == null || entity.Id == default(int))
                {
                    return(null);
                }

                // make sure our list contains the pk
                if (!lookup.ContainsKey(entity.Id))
                {
                    lookup.Add(entity.Id, new CompoundApiResource
                    {
                        ApiResource = entity
                    });
                }

                // fetch the real element
                var tempElem = lookup[entity.Id];

                // add api-scope
                if (apiScope != null)
                {
                    tempElem.ApiResourceScopes.Add(apiScope);
                }

                // add claim
                if (apiClaim != null)
                {
                    tempElem.ApiResourceClaims.Add(apiClaim);
                }

                // add scope
                if (scope != null)
                {
                    tempElem.Scopes.Add(scope);
                }

                return(tempElem);
            }, new { ResName = name }, UnitOfWork.Transaction);
            return(lookup.Values.SingleOrDefault());
        }
Esempio n. 9
0
        /// <summary>	Gets an identity user entity using the given identifier. </summary>
        /// <param name="identifier">	The identifier to get. </param>
        /// <returns>	An IdentityUserEntity. </returns>
        public override IdentityUserEntity Get(string identifier)
        {
            var command =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(IdentityUserEntity)).ToArray())} FROM {TableName} WHERE \"{nameof(IdentityUserEntity.Identifier)}\" = @Identifier";

            return(UnitOfWork.Connection.QuerySingleOrDefault <IdentityUserEntity>(command,
                                                                                   new { Identifier = Guid.Parse(identifier) },
                                                                                   UnitOfWork.Transaction));
        }
Esempio n. 10
0
        /// <summary>	Searches for the first login. </summary>
        /// <param name="providerName">	Name of the provider. </param>
        /// <param name="providerKey">  The provider key. </param>
        /// <returns>	The found login. </returns>
        public override IdentityUserEntity FindByLogin(string providerName, string providerKey)
        {
            var otherTableName = GetTableName(typeof(IdentityUserLoginEntity));
            var command        =
                $"SELECT {SqlBuilder.Adapter.RenderPropertyList(SqlCache.TypePropertiesChache(typeof(IdentityUserEntity)).ToArray())} FROM {TableName} " +
                $"INNER JOIN {otherTableName} ON {TableName}.{nameof(IdentityUserEntity.Identifier)} = {otherTableName}.{nameof(IdentityUserLoginEntity.UserId)} " +
                $"WHERE {otherTableName}.{nameof(IdentityUserLoginEntity.ProviderName)} = @ProviderName " +
                $"AND {otherTableName}.{nameof(IdentityUserLoginEntity.ProviderKey)} = @ProviderKey";

            return(UnitOfWork.Connection.QuerySingleOrDefault <IdentityUserEntity>(command,
                                                                                   new { ProviderName = providerName, ProviderKey = providerKey },
                                                                                   UnitOfWork.Transaction));
        }
Esempio n. 11
0
        /// <summary>	Gets by filter statement. </summary>
        /// <param name="type">			    The type. </param>
        /// <param name="filterProperty">	The filter property. </param>
        /// <param name="selectFields">     The select fields. </param>
        /// <returns>	The by filter statement. </returns>
        public virtual string GetByFilterStatement(Type type, string filterProperty, string[] selectFields)
        {
            var fProp = SqlCache.TypePropertiesChache(type).Single(pi => pi.Name == filterProperty);

            if (selectFields == null || selectFields.Length < 1)
            {
                return
                    ($"SELECT {RenderPropertyList(SqlCache.TypePropertiesChache(type).ToArray())} FROM {RenderTableName(type)} WHERE {RenderPropertyName(fProp)} = {RenderParameterProperty(fProp)}");
            }

            var sProps = SqlCache.TypePropertiesChache(type).Where(pi => selectFields.Contains(pi.Name)).ToArray();

            return
                ($"SELECT {RenderPropertyList(sProps)} FROM {RenderTableName(type)} WHERE {RenderPropertyName(fProp)} = {RenderParameterProperty(fProp)}");
        }
Esempio n. 12
0
 /// <summary>	The select all statement. </summary>
 public virtual string SelectAllStatement(Type type)
 {
     return
         ($"SELECT {RenderPropertyList(SqlCache.TypePropertiesChache(type).ToArray())} FROM {RenderTableName(type)}");
 }
Esempio n. 13
0
 /// <summary>	Gets the columns without keys in this collection. </summary>
 /// <param name="type">	The type. </param>
 /// <returns>
 ///     An enumerator that allows foreach to be used to process the columns without keys in this
 ///     collection.
 /// </returns>
 public virtual IEnumerable <PropertyInfo> GetPropertiesWithoutKey(Type type)
 {
     return(SqlCache.TypePropertiesChache(type).Except(new[] { SqlCache.TypeKeyPropertiesCache(type).Single() }));
 }