Beispiel #1
0
        public ExtJsResult GetAllWithExtResult(int page, int start, int limit, FilterExpression[] filterList, GetDataSourceDelegate <T> dataSourceGetHandler = null, FilterDataSourceDelegate <T> filterHandler = null)
        {
            GetDataSourceDelegate <T> getDataSource = dataSourceGetHandler;

            if (getDataSource == null)
            {
                getDataSource = this.DefaultDataSourceGetHandler;
            }
            FilterDataSourceDelegate <T> filter = filterHandler;

            if (filter == null)
            {
                filter = this.DefaultDataSourceFilter;
            }

            ExtJsResult result = new ExtJsResult();

            CommonRepository.UseDbContext(dbContext =>
            {
                IQueryable <T> dataSource  = filter(getDataSource(dbContext), filterList);
                IQueryable <T> countSource = filter(getDataSource(dbContext), filterList);
                if (start > 0)
                {
                    dataSource = dataSource.Skip(start);
                }
                if (limit > 0)
                {
                    dataSource = dataSource.Take(limit);
                }
                try
                {
                    List <T> list = dataSource.ToList();
                    int count     = countSource.Count();
                    // int count = this.DefaultDataSourceFilter(this.DefaultDataSourceGetHandler(dbContext), filterList).Count();

                    result.RootProperty = list;
                    result.total        = count;
                }
                catch (Exception e)
                {
                    GlobalConstants.DefaultLogger.Error(e.Message);
                }
            });
            return(result);
        }
Beispiel #2
0
        public T GetByOne(FilterExpression[] filterList, GetDataSourceDelegate <T> getDataSourceHandler = null, FilterDataSourceDelegate <T> filterHandler = null)
        {
            GetDataSourceDelegate <T> getDataSource = getDataSourceHandler;

            if (getDataSource == null)
            {
                getDataSource = this.DefaultDataSourceGetHandler;
            }
            FilterDataSourceDelegate <T> filter = filterHandler;

            if (filter == null)
            {
                filter = this.DefaultDataSourceFilter;
            }

            T result = null;

            CommonRepository.UseDbContext(dbContext =>
            {
                IQueryable <T> dataSource = filter(getDataSource(dbContext), filterList);
                result = dataSource.FirstOrDefault();
            });
            return(result);
        }
Beispiel #3
0
 public ExtJsResult GetAllWithExtResult(int page, int start, int limit, string filterStr, GetDataSourceDelegate <T> dataSourceGetHandler = null, FilterDataSourceDelegate <T> filterHandler = null)
 {
     FilterExpression[] filterList = filterStr.ToObject <FilterExpression[]>();
     return(this.GetAllWithExtResult(page, start, limit, filterList, dataSourceGetHandler, filterHandler));
 }