예제 #1
0
        public async Task <RestItemData> GetDataAsync(IEnumerable <string> fieldNames)
        {
            var fieldAuth = new FieldAuthChecker <TItem>(_context.Fields, _context.AuthorizationChecker, _item);
            IEnumerable <string> fields = fieldAuth.GetOrEnsureFields(fieldNames, 0);

            var selector      = new QueryableFieldSelector <TItem>(_context.Fields, fields);
            var loadedObjects = await selector.SelectFieldsOnlyAsync(_item.Query, _context.Repository.ForEachAsync);

            RestItemData loadedObject = ItemQueryHelper.SingleOrThrow(loadedObjects);

            return(loadedObject);
        }
예제 #2
0
        public async Task <RestCollectionData> QueryDataAsync(IRestCollectionQuery query)
        {
            await _context.Repository.InitializeAsync();

            var fieldAuth = new FieldAuthChecker <TItem>(_context.Fields, _context.AuthorizationChecker, null);
            IEnumerable <string> fields = fieldAuth.GetOrEnsureFields(query?.SelectFields, 1);
            var selector = new QueryableFieldSelector <TItem>(_context.Fields.GetReaders(fields));

            var queryBuilder         = new ContextQueryBuilder <TItem>(_context, query);
            IQueryable <TItem> items = queryBuilder.BuildQueryable();

            QueriedDataIterator queriedData = await selector.SelectFieldsOnlyAsync(items, _context.Repository.ForEachAsync);

            PageDetails pageDetails = queryBuilder.GetPageDetails(queriedData);

            return(new RestCollectionData(queriedData, pageDetails));
        }
        public async Task <RestDictionaryData> QueryDataAsync(IRestCollectionQuery query)
        {
            await _context.Repository.InitializeAsync();

            var queryBuilder         = new ContextQueryBuilder <TItem>(_context, query);
            IQueryable <TItem> items = queryBuilder.BuildQueryable();

            var fieldAuth = new FieldAuthChecker <TItem>(_context.Fields, _context.AuthorizationChecker, null);
            IEnumerable <string> fields = fieldAuth.GetOrEnsureFields(query?.SelectFields, 1);

            var readers = _context.Fields.GetReaders(fields);

            readers.Add(IDENTIFIER_FIELD_NAME, new IdentifierFieldReader <TItem>(_namedReferenceInfo));
            var selector = new QueryableFieldSelector <TItem>(readers);

            QueriedDataIterator queriedData = await selector.SelectFieldsOnlyAsync(items, _context.Repository.ForEachAsync);

            PageDetails pageDetails = queryBuilder.GetPageDetails(queriedData);

            var dictionaryData = GetKeys(queriedData).ToDictionary(k => k.Key, v => (object)v.Value);

            return(new RestDictionaryData(dictionaryData, pageDetails));
        }