Exemplo n.º 1
0
        public IActionResult GetName(string key)
        {
            // Get entity type from path.
            ODataPath path = Request.ODataFeature().Path;

            if (path.PathTemplate != "~/entityset/key/property")
            {
                return(BadRequest("Not the correct property access request!"));
            }

            PropertySegment property   = path.Segments.Last() as PropertySegment;
            IEdmEntityType  entityType = property.Property.DeclaringType as IEdmEntityType;

            // Create an untyped entity object with the entity type.
            EdmEntityObject entity = new EdmEntityObject(entityType);

            string sourceString = Request.GetDataSource();

            DataSourceProvider.Get(sourceString, key, entity);

            object value = DataSourceProvider.GetProperty(sourceString, "Name", entity);

            if (value == null)
            {
                return(NotFound());
            }

            string strValue = value as string;

            return(Ok(strValue));
        }
Exemplo n.º 2
0
        // Get entityset(key)
        public IEdmEntityObject Get(string key)
        {
            // Get entity type from path.
            ODataPath      path       = Request.ODataProperties().Path;
            IEdmEntityType entityType = (IEdmEntityType)path.EdmType;

            // Create an untyped entity object with the entity type.
            EdmEntityObject entity = new EdmEntityObject(entityType);

            DataSourceProvider.Get((string)Request.Properties[Constants.ODataDataSource], key, entity);

            return(entity);
        }
Exemplo n.º 3
0
        // Get entityset(key)
        public IEdmEntityObject Get(string key)
        {
            // Get entity type from path.
            ODataPath      path       = Request.ODataFeature().Path;
            IEdmEntityType entityType = (IEdmEntityType)path.EdmType;

            // Create an untyped entity object with the entity type.
            EdmEntityObject entity = new EdmEntityObject(entityType);

            string sourceString = Request.GetDataSource();

            DataSourceProvider.Get(sourceString, key, entity);

            return(entity);
        }
Exemplo n.º 4
0
        // Get entityset
        public EdmEntityObjectCollection Get()
        {
            // Get entity set's EDM type: A collection type.
            ODataPath               path           = Request.ODataProperties().Path;
            IEdmCollectionType      collectionType = (IEdmCollectionType)path.EdmType;
            IEdmEntityTypeReference entityType     = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            // Add untyped objects to collection.
            DataSourceProvider.Get((string)Request.Properties[Constants.ODataDataSource], entityType, collection);

            return(collection);
        }
Exemplo n.º 5
0
        // Get entityset
        public IActionResult Get()
        {
            // Get entity set's EDM type: A collection type.
            ODataPath               path           = Request.ODataFeature().Path;
            IEdmCollectionType      collectionType = (IEdmCollectionType)path.EdmType;
            IEdmEntityTypeReference entityType     = collectionType.ElementType.AsEntity();

            // Create an untyped collection with the EDM collection type.
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));

            string sourceString = Request.GetDataSource();

            // Add untyped objects to collection.
            DataSourceProvider.Get(sourceString, entityType, collection);

            return(collection);
        }
Exemplo n.º 6
0
        public IActionResult GetNavigation(string key, string navigation)
        {
            ODataPath path = Request.ODataFeature().Path;

            if (path.PathTemplate != "~/entityset/key/navigation")
            {
                return(BadRequest("Not the correct navigation property access request!"));
            }

            NavigationPropertySegment property = path.Segments.Last() as NavigationPropertySegment;

            if (property == null)
            {
                return(BadRequest("Not the correct navigation property access request!"));
            }

            IEdmEntityType entityType = property.NavigationProperty.DeclaringType as IEdmEntityType;

            EdmEntityObject entity = new EdmEntityObject(entityType);

            string sourceString = Request.GetDataSource();

            DataSourceProvider.Get(sourceString, key, entity);

            object value = DataSourceProvider.GetProperty(sourceString, navigation, entity);

            if (value == null)
            {
                return(NotFound());
            }

            IEdmEntityObject nav = value as IEdmEntityObject;

            if (nav == null)
            {
                return(NotFound());
            }

            return(Ok(nav));
        }