示例#1
0
        /// <summary>
        /// Returns a list of dynamic rows and optionally their count as per the specifications in <paramref name="args"/>.
        /// </summary>
        public virtual async Task <FactResult> GetFact(FactArguments args, CancellationToken cancellation)
        {
            await Initialize(cancellation);

            // Parse the parameters
            var filter  = ExpressionFilter.Parse(args.Filter);
            var orderby = ExpressionOrderBy.Parse(args.OrderBy);
            var select  = ExpressionFactSelect.Parse(args.Select);

            // Prepare the query
            var query = QueryFactory().FactQuery <TEntity>();

            // Apply read permissions
            var permissionsFilter = await UserPermissionsFilter(PermissionActions.Read, cancellation);

            query = query.Filter(permissionsFilter);

            // Apply filter
            query = query.Filter(filter);

            // Apply orderby
            orderby ??= await DefaultOrderBy(cancellation);

            query = query.OrderBy(orderby);

            // Apply the paging (Protect against DOS attacks by enforcing a maximum page size)
            var top  = args.Top;
            var skip = args.Skip;

            top   = Math.Min(top, MaximumPageSize());
            query = query.Skip(skip).Top(top);

            // Apply the select
            query = query.Select(select);

            // Load the data and count in memory
            List <DynamicRow> data;
            int?count = null;

            if (args.CountEntities)
            {
                (data, count) = await query.ToListAndCountAsync(MaximumCount, QueryContext, cancellation);
            }
            else
            {
                data = await query.ToListAsync(QueryContext, cancellation);
            }

            // Return
            return(new FactResult(data, count));
        }
示例#2
0
        public virtual async Task <ActionResult <GetFactResponse> > GetFact([FromQuery] FactArguments args, CancellationToken cancellation)
        {
            // Calculate server time at the very beginning for consistency
            var serverTime = DateTimeOffset.UtcNow;

            // Retrieves the raw data from the database, unflattend, untrimmed
            var service = GetFactService();
            var result  = await service.GetFact(args, cancellation);

            var data  = result.Data;
            var count = result.Count;

            // Prepare the result in a response object
            var response = new GetFactResponse
            {
                ServerTime = serverTime,
                Result     = data,
                TotalCount = count
            };

            return(Ok(response));
        }