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
        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));
        }