Exemple #1
0
        public IRestResource GetField(string fieldName)
        {
            if (!_context.Fields.FieldExists(fieldName))
            {
                throw new FieldNotFoundException(fieldName, true);
            }

            var namedField = new NamedField <TItem>(fieldName, _context.Fields);

            if (!_context.AuthorizationChecker.CanGetField(_item, namedField))
            {
                throw new NotAuthorizedForFieldException(AuthorizableVerb.Get, fieldName);
            }

            IRestResource fullResource = _context.Fields.GetFullResource(fieldName, _item, _context.Transaction);

            if (fullResource != null)
            {
                return(fullResource);
            }

            if (ScalarFieldHelper.IsScalarType(namedField.Reader.FieldType))
            {
                return(new EngineRestScalar <TItem>(_context, _item, namedField));
            }

            return(new EngineRestPoco <TItem>(_context, _item, namedField));
        }
        public async Task <object> GetAsync()
        {
            if (!_context.AuthorizationChecker.CanGetField(_item, _field))
            {
                throw new NotAuthorizedForFieldException(AuthorizableVerb.Get, _field.Name);
            }

            return(await ScalarFieldHelper.LoadScalarValueAsync(_field.Reader, _item.Query, _context.Repository.ForEachAsync));
        }