Ejemplo n.º 1
0
        public static GridMetadata ProcessMetadata(this GridRequest request, Object entity)
        {
            var metadata = new GridMetadata();

            var filterValues = request.Filters.Select(x => x.Value.ToString()).ToList();

            filterValues = filterValues.ToList();


            if (request.SearchTerm != null && request.SearchTerm != String.Empty)
            {
                filterValues.Add(request.SearchTerm);
                metadata.WhereString = $"({request.Filters.FilterString()}) and ({request.SearchString(entity)})";
            }
            else
            {
                metadata.WhereString = $"({request.Filters.FilterString()})";
            }

            metadata.WhereValues   = filterValues.ToArray();
            metadata.OrderByString = request.OrderBy.OrderByString();
            metadata.SelectString  = request.Select.SelectString();
            metadata.TakeCount     = request.PageSize;
            metadata.SkipCount     = (request.PageNumber - 1) * request.PageSize;

            return(metadata);
        }
Ejemplo n.º 2
0
        public static async Task <GridResponse> ExecuteGridQuery(this IQueryable query, GridMetadata metadata, bool allData = false)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            var response = new GridResponse();

            //// Total Count After Security
            //response.TotalCount = query.Count();

            // Adding Requested Filters
            query = query.Where(metadata.WhereString, metadata.WhereValues);

            // Count after filters
            response.FilteredCount = query.Count();
            response.TotalCount    = response.FilteredCount;

            if (metadata.OrderByString != null)
            {
                query = query.OrderBy(metadata.OrderByString);
            }

            if (metadata.SelectString != null)
            {
                query = query.Select(metadata.SelectString);
            }

            if (allData)
            {
                response.Data = await query.ToDynamicListAsync();
            }
            else
            {
                response.Data = await query.Skip(metadata.SkipCount).Take(metadata.TakeCount).ToDynamicListAsync();
            }

            stopWatch.Stop();
            response.QueryExecutionMs = stopWatch.ElapsedMilliseconds;

            return(response);
        }