Exemplo n.º 1
0
 /// <summary>Initializes a new instance of the <see cref="T:Common.Features.Cruds.Filterable.EntitySqlFilterOperation" /> class.</summary>
 public EntitySqlFilterOperation(EntitySqlFilterOperationParameters parameters, SqlFilterStatementParser <TEntity, TFilterableEntity, TKey> filterStatementParser)
 {
     _parameters            = parameters;
     _filterStatementParser = filterStatementParser;
     ShouldContains(_parameters.Sql, WhereClause);
     ShouldContains(_parameters.Sql, OrderByClause);
     ShouldContains(_parameters.Sql, PaggingClause);
 }
Exemplo n.º 2
0
        public ResourcePointConfigurator <TEntity, TFilterableEntity, TKey> UseFilterableEntityOperation <TFilterableOperation>(Action <EntitySqlFilterOperationParameters> config)
            where TFilterableOperation : EntitySqlFilterOperation <TEntity, TFilterableEntity, TKey>
        {
            _filterableEntityOperation = typeof(TFilterableOperation);
            var parameters = new EntitySqlFilterOperationParameters();

            config(parameters);
            _filterableEntityOperationParameters = parameters;
            return(this);
        }
        private bool AddStatement(bool isFirst, FilterStatement filterStatement, List <object> parameterList, StringBuilder whereBuilder, EntitySqlFilterOperationParameters operationParameters)
        {
            var currentIndex = parameterList.Count;

            var value = FilterTypeCorrector.ChangeType <TFilterableEntity>(filterStatement.ParameterName, filterStatement.ParameterValue);

            if (value == null)
            {
                return(false);
            }

            parameterList.Add(value);

            if (!isFirst)
            {
                if (filterStatement.LogicalOperator == FilterLogicalOperators.Or)
                {
                    whereBuilder.Append(" OR ");
                }
                else
                {
                    whereBuilder.Append(" AND ");
                }
            }

            var columnName = CreateColumnName(filterStatement.ParameterName, operationParameters);

            CreateLogicalOperation(whereBuilder, columnName, currentIndex, filterStatement.ComparisonOperator);

            return(true);
        }
        public (string where, object[] parameters) Parse(IList <FilterStatement> statements, EntitySqlFilterOperationParameters operationParameters)
        {
            var parameterList = new List <object>();

            var whereBuilder = new StringBuilder();

            whereBuilder.Append(" WHERE (");
            AddIsDeleted(parameterList, whereBuilder, operationParameters);
            TryAddTenant(parameterList, whereBuilder, operationParameters);

            whereBuilder.Append(" )");

            if (statements.Any())
            {
                whereBuilder.Append(" AND ( ");

                var isFirst = true;
                foreach (var filterStatement in statements)
                {
                    var added = AddStatement(isFirst, filterStatement, parameterList, whereBuilder, operationParameters);

                    if (added)
                    {
                        isFirst = false;
                    }
                }

                whereBuilder.Append(" ) ");
            }


            return(whereBuilder.ToString(), parameterList.ToArray());
        }