Ejemplo n.º 1
0
        public ExtJsResult GetWorkshopLocList(long workshopId)
        {
            WorkstationLogic workstationLogic = this.Logic as WorkstationLogic;
            List <string>    locList          = workstationLogic.GetWorkshopLocList(workshopId);
            ExtJsResult      result           = new ExtJsResult();

            result.RootProperty = locList.Select(x => new { locCode = x }).ToList();
            result.total        = locList.Count;
            return(result);
        }
Ejemplo n.º 2
0
        protected virtual ExtJsResult CreateResult()
        {
            var result = new ExtJsResult(Page.Response)
            {
                data    = new[] { Entity },
                success = true,
                msg     = "",
                total   = 1
            };

            return(result);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public ExtJsResult GetStationByWorkshop(long workshopId)
        {
            IQueryCollection query = this.HttpContext.Request.Query;

            int page  = int.Parse(query["page"][0]);
            int start = int.Parse(query["start"][0]);
            int limit = int.Parse(query["limit"][0]);
            FilterExpression expression = new FilterExpression()
            {
                L = "parentId",
                O = "=",
                R = workshopId.ToString()
            };

            ExtJsResult result = Logic.GetAllWithExtResult(page, start, limit, new FilterExpression[] { expression });

            return(result);
        }
Ejemplo n.º 5
0
        public override ExtJsResult ExecuteQuery()
        {
            var query = _query;

            var filterFn = _page.Server.UrlDecode(_page.Request.Unvalidated["filter"]);

            if (!filterFn.IsEmpty())
            {
                var filtersArray = Json.Decode(filterFn);
                foreach (var filter in filtersArray)
                {
                    string key = filter.property ?? filter.field;
                    if (string.IsNullOrEmpty(key) || !_filters.ContainsKey(key))
                    {
                        continue;
                    }

                    var tempExpr = _filters[key];
                    var resExpr  = Lambda.ModifyExpression(tempExpr, (object)filter.value);

                    query = query.Where(resExpr);
                }
            }

            var isOrdered = false;

            var sortFn = _page.Server.UrlDecode(_page.Request.Unvalidated["sort"]);

            if (!sortFn.IsEmpty())
            {
                var sortersArray = Json.Decode(sortFn);
                foreach (var sort in sortersArray)
                {
                    string key = sort.property;
                    if (!string.IsNullOrEmpty(key) && _sorters.ContainsKey(key))
                    {
                        var expr = _sorters[key];
                        if (isOrdered)
                        {
                            var ordered = query as IOrderedQueryable <TEntity>;
                            query = ordered.ThenBy(expr);
                        }
                        else
                        {
                            query = query.OrderBy(expr);
                        }

                        isOrdered = true;
                    }
                }
            }

            if (isOrdered)
            {
                //var ordered = (IOrderedQueryable<TEntity>)query;
                //query = ordered.ThenBy(_setOrderBy(ordered));
            }
            else
            {
                query = _orderByExpression(query);
            }

            var total = query.Count();

            if (!_page.Request["limit"].IsEmpty())
            {
                var start = _page.Request["start"].AsInt(0);
                if (start > total)
                {
                    start = 0;
                }

                var limit = _page.Request["limit"].AsInt(25);

                query = query.Skip(start).Take(limit);
            }

            var result = new ExtJsResult(_page.Response)
            {
                msg     = "",
                success = true,
                total   = total,
                data    = query.ToList()
            };

            return(result);
        }