Esempio n. 1
0
        private ICollection <WebAPIDto <THeader> > AttachTenantFilter(IEnumerable <WebAPIDto <THeader> > source)
        {
            if (FilterExpressions == null || !FilterExpressions.Any(x => x.Key.Contains("TenantModel")))
            {
                return(source.ToList());
            }

            try
            {
                foreach (KeyValuePair <string, IFilterExpression> filter in FilterExpressions.Where(x => x.Key.Contains("TenantModel")))
                {
                    ParameterExpression param  = Expression.Parameter(typeof(WebAPIDto <THeader>), "x");
                    string[]            parts  = filter.Value.PropertyName.Replace("Entity.", "").Split('.');
                    Expression          parent = param;
                    foreach (string part in parts)
                    {
                        parent = Expression.Property(parent, part);
                    }

                    ConstantExpression constant = Expression.Constant(filter.Value.FilterValue);
                    Expression         expr     = Expression.Equal(parent, constant);
                    source = source.AsQueryable().Where(Expression.Lambda <Func <WebAPIDto <THeader>, bool> >(expr, param));
                }
            }
            catch (Exception ex)
            {
                throw new DocSuiteException("Errore filtro", "Espressione di filtro non corretta", ex);
            }
            return(source.ToList());
        }
Esempio n. 2
0
        protected virtual bool AttachFilterExpressions(ref IODATAQueryManager odataQuery)
        {
            if (FilterExpressions == null)
            {
                return(false);
            }

            try
            {
                foreach (KeyValuePair <string, IFilterExpression> filter in FilterExpressions.Where(x => !x.Key.Contains("TenantModel")))
                {
                    string expr = GetExpression(filter.Value);
                    odataQuery.Filter(expr);
                }
            }
            catch (Exception ex)
            {
                throw new DocSuiteException("Errore filtro", "Espressione di filtro non corretta", ex);
            }
            return(true);
        }