コード例 #1
0
        protected virtual async Task <bool> HasAccessToAsync(params object[] keyValues)
        {
            if (keyValues == null || keyValues.Length == 0)
            {
                return(false);
            }
            QueryObject <TEntityVM> queryObject = new QueryObject <TEntityVM>();
            Expression <Func <TEntityVM, bool> > defaultSearchExpr = this.CreateDefaultSearchExpression();

            if (defaultSearchExpr != null)
            {
                queryObject.And(defaultSearchExpr);
            }
            Expression <Func <TEntityVM, bool> > idExpr = new FilterInfo()
            {
                Filters =
                {
                    new FilterData()
                    {
                        Field    = "ID",
                        Operator = "eq",
                        Value    = keyValues[0].ToString()
                    }
                }
            }.TranslateFilter <TEntityVM>(false);

            if (idExpr != null)
            {
                queryObject.And(idExpr);
            }
            IQueryable <TEntity>   query       = this.BusinessRule.Queryable(false, true, (List <Expression <Func <TEntity, object> > >)null);
            IQueryable <TEntityVM> searchQuery = this.CreateSearchQuery(query);

            if (queryObject.Query() != null)
            {
                searchQuery = searchQuery.Where <TEntityVM>(queryObject.Query());
            }
            bool hasAccess = false;

            if ((object)new TEntity() is ICacheable)
            {
                hasAccess = await Task.Run <bool>((Func <bool>)(() => searchQuery.Any <TEntityVM>()));
            }
            else
            {
                hasAccess = await searchQuery.AnyAsync <TEntityVM>();
            }
            if (!hasAccess)
            {
                await ExceptionManager.SaveExceptionAsync((Exception) new OperationAccessException(string.Format("id: {0}, controller: {1}, userName: {2}", keyValues[0], (object)this.GetType().Name, (object)SecurityManager.CurrentUserContext.UserName)));
            }
            return(hasAccess);
        }
コード例 #2
0
        protected Expression <Func <TEntityVM, bool> > CreateSearchExpression(
            FilterInfo filterInfo)
        {
            QueryObject <TEntityVM> queryObject = new QueryObject <TEntityVM>();
            Expression <Func <TEntityVM, bool> > searchExpression = this.CreateDefaultSearchExpression();

            if (searchExpression != null)
            {
                queryObject.And(searchExpression);
            }
            Expression <Func <TEntityVM, bool> > expressionByFilterInfo = this.CreateSearchExpressionByFilterInfo(filterInfo);

            if (expressionByFilterInfo != null)
            {
                queryObject.And(expressionByFilterInfo);
            }
            return(queryObject.Query());
        }
コード例 #3
0
        protected virtual bool HasAccessTo(params object[] keyValues)
        {
            if (keyValues == null || keyValues.Length == 0)
            {
                return(false);
            }
            QueryObject <TEntityVM> queryObject = new QueryObject <TEntityVM>();
            Expression <Func <TEntityVM, bool> > searchExpression = this.CreateDefaultSearchExpression();

            if (searchExpression != null)
            {
                queryObject.And(searchExpression);
            }
            Expression <Func <TEntityVM, bool> > query = new FilterInfo()
            {
                Filters =
                {
                    new FilterData()
                    {
                        Field    = "ID",
                        Operator = "eq",
                        Value    = keyValues[0].ToString()
                    }
                }
            }.TranslateFilter <TEntityVM>(false);

            if (query != null)
            {
                queryObject.And(query);
            }
            IQueryable <TEntityVM> source = this.CreateSearchQuery(this.BusinessRule.Queryable(false, true, (List <Expression <Func <TEntity, object> > >)null));

            if (queryObject.Query() != null)
            {
                source = source.Where <TEntityVM>(queryObject.Query());
            }
            bool flag = source.Any <TEntityVM>();

            if (!flag)
            {
                ExceptionManager.SaveException((Exception) new OperationAccessException(string.Format("id: {0}, controller: {1}, userName: {2}", keyValues[0], (object)this.GetType().Name, (object)SecurityManager.CurrentUserContext.UserName)));
            }
            return(flag);
        }
コード例 #4
0
ファイル: GridRequest.cs プロジェクト: cuongdn/mmisc
        public QueryObject <T> GetFilters <T>()
        {
            var queryObject = new QueryObject <T>();

            foreach (var filter in Filters)
            {
                queryObject.And(filter.FilterExpression, filter.ConvertedValue);
            }
            return(queryObject);
        }
コード例 #5
0
ファイル: BaseService.cs プロジェクト: BrutalHex/WalletPan
        private Expression <Func <TEntity, bool> > CreateSearchExpression <TEntity>(FilterInfo filterInfo) where TEntity : class
        {
            QueryObject <TEntity> queryObject             = new QueryObject <TEntity>();
            Expression <Func <TEntity, bool> > searchExpr = CreateSearchExpressionByFilterInfo <TEntity>(filterInfo);

            if (searchExpr != null)
            {
                queryObject.And(searchExpr);
            }

            return(queryObject.Query());
        }
コード例 #6
0
ファイル: FilterInfo.cs プロジェクト: manyar98/Zhivar
        public Expression <Func <TEntity, bool> > TranslateFilter <TEntity>(
            bool processPersianChars = true)
            where TEntity : class
        {
            QueryObject <TEntity> queryObject         = new QueryObject <TEntity>();
            ParameterExpression   parameterExpression = Expression.Parameter(typeof(TEntity), "entity");

            foreach (FilterData filter in this.Filters)
            {
                if (filter.Filters != null && filter.Filters.Any <FilterData>())
                {
                    Expression <Func <TEntity, bool> > query = new FilterInfo()
                    {
                        Logic   = filter.Logic,
                        Filters = filter.Filters
                    }.TranslateFilter <TEntity>(true);
                    if (string.IsNullOrWhiteSpace(this.Logic))
                    {
                        queryObject.And(query);
                    }
                    else if (this.Logic.ToLower() == "and")
                    {
                        queryObject.And(query);
                    }
                    else
                    {
                        queryObject.Or(query);
                    }
                }
                else if (processPersianChars && filter.Value != null && (filter.Value.Contains("ي") || filter.Value.Contains("ك") || filter.Value.Contains("ی") || filter.Value.Contains("ک")))
                {
                    FilterInfo filterInfo = new FilterInfo()
                    {
                        Logic = "or"
                    };
                    filterInfo.Filters.Add(filter);
                    string str = "";
                    if (filter.Value.Contains("ي") || filter.Value.Contains("ك"))
                    {
                        str = filter.Value.Replace("ي", "ی").Replace("ك", "ک");
                    }
                    else if (filter.Value.Contains("ی") || filter.Value.Contains("ک"))
                    {
                        str = filter.Value.Replace("ی", "ي").Replace("ک", "ك");
                    }
                    filterInfo.Filters.Add(new FilterData()
                    {
                        Field    = filter.Field,
                        Logic    = filter.Logic,
                        Operator = filter.Operator,
                        Value    = str
                    });
                    Expression <Func <TEntity, bool> > query = filterInfo.TranslateFilter <TEntity>(false);
                    if (string.IsNullOrWhiteSpace(this.Logic))
                    {
                        queryObject.And(query);
                    }
                    else if (this.Logic.ToLower() == "and")
                    {
                        queryObject.And(query);
                    }
                    else
                    {
                        queryObject.Or(query);
                    }
                }
                else
                {
                    string     mapPropertyName = PropertyMapCollection.GetMapPropertyName <TEntity>(filter.Field);
                    Expression bodyExpression  = FilterInfo.CreateBodyExpression(parameterExpression, mapPropertyName, filter.Operator, filter.Value);
                    if (bodyExpression != null)
                    {
                        Expression <Func <TEntity, bool> > query = Expression.Lambda <Func <TEntity, bool> >(bodyExpression, parameterExpression);
                        if (string.IsNullOrWhiteSpace(this.Logic))
                        {
                            queryObject.And(query);
                        }
                        else if (this.Logic.ToLower() == "and")
                        {
                            queryObject.And(query);
                        }
                        else
                        {
                            queryObject.Or(query);
                        }
                    }
                }
            }
            return(queryObject.Query());
        }