public MethodInfo GetMapperMethod <TEntity>() { string entityName = typeof(TEntity).Name; string mapperTypeName = string.Format( "{0}.{1}Mapper", EdFiConventions.BuildNamespace(Namespaces.Entities.Common.BaseNamespace, EdFiConventions.ProperCaseName), entityName); // TODO: Embedded convention - Mapper type namespace var mapperType = Type.GetType( mapperTypeName + ", " + typeof(Marker_EdFi_Ods_Standard).Assembly.GetName() .Name); BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; var mapperMethod = mapperType.GetMethod("MapTo", bindingFlags); if (mapperMethod == null) { mapperMethod = mapperType.GetMethod("MapDerivedTo", bindingFlags); if (mapperMethod == null) { throw new Exception($"Unable to find MapTo or MapDerivedTo method on type '{mapperType.FullName}'."); } } return(mapperMethod); }
protected override void Act() { _actualResult = EdFiConventions.BuildNamespace( $"{Namespaces.Resources.BaseNamespace}", EdFiConventions.ProperCaseName); }
protected override object Build() { return(new { CommonRecordsNamespace = EdFiConventions.BuildNamespace( Namespaces.Entities.Records.BaseNamespace, TemplateContext.SchemaProperCaseName), Interfaces = TemplateContext.DomainModelProvider.GetDomainModel() .Entities .Where(TemplateContext.ShouldRenderEntity) .Select( e => new { e.Schema, AggregateRootName = e.Aggregate.AggregateRoot.Name, EntityName = e.Name, EntityProperties = e.EntityRecordInterfaceUnifiedProperties() .OrderBy( p => p.PropertyName) .Select( p => new { PropertyType = p.PropertyType.ToCSharp(true), CSharpSafePropertyName = p.PropertyName.MakeSafeForCSharpClass(e.Name) }) }) }); }
protected override void Act() { _actualResult = EdFiConventions.BuildNamespace( $"{Namespaces.Resources.BaseNamespace}", "Sample", "StaffExtension", isExtensionObject: true); }
private string GetNamespace(Resource resource) { return (EdFiConventions.BuildNamespace( Namespaces.Requests.BaseNamespace, TemplateContext.SchemaProperCaseName, resource.Entity.PluralName, resource.Entity.IsExtensionEntity)); }
private string FormatControllersNamespace(StandardizedResourceProfileData resourceData) { return(string.Format( "{0}{1}", EdFiConventions.BuildNamespace( BaseNamespaceName, TemplateContext.GetSchemaProperCaseNameForResource(resourceData.ResolvedResource), resourceData.ResolvedResource.PluralName, resourceData.ResolvedResource.Entity.IsExtensionEntity), resourceData.ProfileNamespaceSection)); }
protected override object Build() { var model = new { ClaimsNamespace = Namespaces.Common.Claims, EntitiesNamespace = EdFiConventions.BuildNamespace( Namespaces.Entities.Common.BaseNamespace, TemplateContext.SchemaProperCaseName), AuthorizationStrategyNamespace = Namespaces.Security.Relationships, AggregateEntityIncludes = GetAggregateEntityIncludes() .Select( i => new { Include = i }), ContextDataProviderNamespace = EdFiConventions.BuildNamespace( Namespaces.Security.ContextDataProviders, TemplateContext.SchemaProperCaseName), ResourcesToRender = _authorizationPropertiesByResource.Select( r => new { r.Key.Entity.Schema, ResourceName = r.Key.Name, ResourceNameCamelCase = r.Key.Name.ToCamelCase(), SchemaIsEdFi = r.Key.IsEdFiResource(), AuthorizationResourceProperties = r.Value.OrderBy(p => p.PropertyName) .Select( p => new { ContextPropertyIsIncludedAndNumeric = p.IsIncluded && p .IsNumeric, ContextPropertyIsIncludedOrNumeric = p.IsIncluded ^ p .IsNumeric, ContextPropertyIsNotIncludedAndNumeric = !p.IsIncluded && p .IsNumeric, ContextPropertyName = p.PropertyName, ContextPropertyType = p.PropertyType, ContextPropertyReason = p.Reason, p.IsIdentifying, p.IsIncluded }) }) }; return(model); }
private string GetNamespace(Resource resource, string profileName) { string baseNamespace = EdFiConventions.BuildNamespace( Namespaces.Requests.BaseNamespace, TemplateContext.GetSchemaProperCaseNameForResource(resource), resource.Entity.PluralName, resource.Entity.IsExtensionEntity); return(string.Format( "{0}.{1}", baseNamespace, GetProfileNamespaceName(profileName))); }
protected override object Build() { var resources = ResourceModelProvider.GetResourceModel() .GetAllResources(); var aggregates = resources .Select( r => new { ResourceName = r.Name, ResourceClasses = // Add the root resource class (if it's not abstract or it has a composite id) (r.Entity?.IsAbstractRequiringNoCompositeId() != true && TemplateContext.ShouldRenderResourceClass(r) ? new ResourceClassBase[] { r } : new ResourceClassBase[0]) // Add in non-inherited child items .Concat( r.AllContainedItemTypes .Where( t => TemplateContext.ShouldRenderResourceClass(t) && !t.IsInheritedChildItem)) .ToList() }) .Where(x => x.ResourceClasses.Any()) .OrderBy(x => x.ResourceName) .Select( x => new { AggregateName = x.ResourceName, Mappers = x.ResourceClasses .OrderBy(y => y.Name) .Select(BuildMapper) }); var hasDerivedResources = resources.Any(r => r.IsDerived); return(new { HasDerivedResources = hasDerivedResources, NamespaceName = EdFiConventions.BuildNamespace( Namespaces.Entities.Common.BaseNamespace, TemplateContext.SchemaProperCaseName), Aggregates = aggregates }); }
private string FormatEntityInterface(ResourceClassBase resource) { string properCaseName = resource.IsEdFiResource() ? TemplateContext.SchemaProperCaseName : resource.ResourceModel.SchemaNameMapProvider .GetSchemaMapByPhysicalName(resource.Entity.Schema) .ProperCaseName; return(RemoveEdFiNamespacePrefix( string.Format( "{0}.I{1}", EdFiConventions.BuildNamespace( Namespaces.Entities.Common.BaseNamespace, properCaseName), resource.Name))); }
private string FormatDeleteRequest(StandardizedResourceProfileData resourceData) { //For some reason delete is included in the read only profiles. //If that ever changes: //FormatWritableRequest(resourceData, "Delete"); return(string.Format( "{0}{1}.{2}{3}", EdFiConventions.BuildNamespace( Namespaces.Requests.RelativeNamespace, TemplateContext.GetSchemaProperCaseNameForResource(resourceData.ResolvedResource), resourceData.ResolvedResource.PluralName, resourceData.ResolvedResource.Entity.IsExtensionEntity), resourceData.ProfileNamespaceSection, resourceData.ResolvedResource.Name, "Delete")); }
private string FormatWritableRequest(StandardizedResourceProfileData resourceData, string requestType) { if (resourceData.Writable == null) { return(FormatNullWriteRequest(resourceData)); } return(string.Format( "{0}{1}.{2}{3}", EdFiConventions.BuildNamespace( Namespaces.Requests.RelativeNamespace, TemplateContext.GetSchemaProperCaseNameForResource(resourceData.ResolvedResource), resourceData.Writable.PluralName, resourceData.Writable.Entity.IsExtensionEntity), resourceData.ProfileNamespaceSection, resourceData.Writable.Name, requestType)); }
protected override object Build() { var profileDatas = _resourceProfileProvider .GetResourceProfileData() .ToList(); var schemaNameMapProvider = TemplateContext.DomainModelProvider.GetDomainModel() .SchemaNameMapProvider; // NOTE: for model matching only we need to include abstract models return(new { ResourceContexts = profileDatas .SelectMany(CreateResourceContextModels) .Where(rc => rc != null) .ToList(), SchemaNamespaces = GetSchemaProperCaseNames(profileDatas, schemaNameMapProvider) .Select( x => new { Namespace = EdFiConventions.BuildNamespace(Namespaces.Entities.Common.BaseNamespace, x) }), ProperCaseName = TemplateContext.SchemaProperCaseName, IsExtensionContext = TemplateContext.IsExtension }); }
protected override object Build() { var resourceClassesToRender = ResourceModelProvider.GetResourceModel() .GetAllResources() .SelectMany( r => r.AllContainedItemTypesOrSelf.Where( i => TemplateContext.ShouldRenderResourceClass(i) // Don't render artifacts for base class children in the context of derived resources && !i.IsInheritedChildItem())) .OrderBy(r => r.Name) .ToList(); var entityInterfacesModel = new { EntitiesBaseNamespace = EdFiConventions.BuildNamespace( Namespaces.Entities.Common.BaseNamespace, TemplateContext.SchemaProperCaseName), Interfaces = resourceClassesToRender .Where(TemplateContext.ShouldRenderResourceClass) .Select( r => new { r.FullName.Schema, r.Name, AggregateName = r.Name, ImplementedInterfaces = GetImplementedInterfaceString(r), ParentInterfaceName = GetParentInterfaceName(r), ParentClassName = GetParentClassName(r), IdentifyingProperties = r .IdentifyingProperties // Exclude inherited identifying properties where the property has not been renamed .Where( p => !( p.EntityProperty ?.IsInheritedIdentifying == true && !p .EntityProperty ?.IsInheritedIdentifyingRenamed == true)) .OrderBy( p => p .PropertyName) .Select( p => new { p.IsServerAssigned, IsUniqueId = UniqueIdSpecification .IsUniqueId( p.PropertyName) && PersonEntitySpecification .IsPersonEntity( r.Name), p.IsLookup, CSharpType = p .PropertyType .ToCSharp( false), Name = p .PropertyName, CSharpSafePropertyName = p .PropertyName .MakeSafeForCSharpClass( r.Name), LookupName = p .PropertyName }) .ToList(), r.IsDerived, InheritedNonIdentifyingProperties = r.IsDerived ? r.AllProperties .Where(p => p.IsInherited && !p.IsIdentifying) .OrderBy(p => p.PropertyName) .Where(IsModelInterfaceProperty) .Select( p => new { p.IsLookup, CSharpType = p.PropertyType.ToCSharp(true), Name = p.PropertyName, LookupName = p.PropertyName.TrimSuffix("Id") }) .ToList() : null, NonIdentifyingProperties = r.NonIdentifyingProperties .Where(p => !p.IsInherited) .OrderBy(p => p.PropertyName) .Where(IsModelInterfaceProperty) .Select( p => new { p.IsLookup, CSharpType = p.PropertyType.ToCSharp(true), Name = p.PropertyName, CSharpSafePropertyName = p.PropertyName .MakeSafeForCSharpClass(r.Name), LookupName = p.PropertyName.TrimSuffix("Id") }) .ToList(), HasNavigableOneToOnes = r.EmbeddedObjects.Any(), NavigableOneToOnes = r .EmbeddedObjects .Where(eo => !eo.IsInherited) .OrderBy( eo => eo .PropertyName) .Select( eo => new { Name = eo .PropertyName }) .ToList(), InheritedLists = r.IsDerived ? r.Collections .Where(c => c.IsInherited) .OrderBy(c => c.PropertyName) .Select( c => new { c.ItemType.Name, PluralName = c.PropertyName }) .ToList() : null, Lists = r.Collections .Where(c => !c.IsInherited) .OrderBy(c => c.PropertyName) .Select( c => new { c.ItemType.Name, PluralName = c.PropertyName }) .ToList(), HasDiscriminator = r.HasDiscriminator(), AggregateReferences = r.Entity?.GetAssociationsToReferenceableAggregateRoots() .OrderBy(a => a.Name) .Select( a => new { AggregateReferenceName = a.Name, MappedReferenceDataHasDiscriminator = a.OtherEntity.HasDiscriminator() }) .ToList() }) .ToList() }; return(entityInterfacesModel); }
private object CreateResourceClass(ResourceProfileData profileData, ResourceClassBase resourceClass) { // NOTE model matching if (resourceClass.IsAbstract()) { return(new { ResourceReference = new { ReferenceName = resourceClass.Name, ReferenceIdentifiers = _resourcePropertyRenderer.AssembleIdentifiers(profileData, resourceClass), Href = AssembleHref(profileData, resourceClass), HasDiscriminator = resourceClass.HasDiscriminator() }, ShouldRenderClass = false, HasDiscriminator = resourceClass.HasDiscriminator() }); } var parentResource = (resourceClass as ResourceChildItem)?.Parent; // NOTE model matching if (parentResource != null && parentResource.IsAbstract() && parentResource.Entity?.IsSameAggregate(resourceClass.Entity) != true) { return(new { ShouldRenderClass = false }); } object putPostRequestValidator = _resourceCollectionRenderer.CreatePutPostRequestValidator(profileData, resourceClass, TemplateContext); // Contextual parent handling var resourceAsChildItem = resourceClass as ResourceChildItem; var contextualParent = GetContextualParent(resourceAsChildItem, profileData); var parentProperCaseSchemaName = contextualParent?.ResourceModel.SchemaNameMapProvider .GetSchemaMapByPhysicalName(contextualParent.FullName.Schema) .ProperCaseName; var collections = _resourceCollectionRenderer.Collections(profileData, resourceClass, TemplateContext); return(new { ShouldRenderClass = true, ResourceReference = resourceClass.IsAggregateReference() ? new { ReferenceName = resourceClass.Name, ReferenceIdentifiers = _resourcePropertyRenderer .AssembleIdentifiers(profileData, resourceClass), Href = AssembleHref(profileData, resourceClass) } : ResourceRenderer.DoNotRenderProperty, ContextSpecificResourceReferences = CreateContextSpecificResourceReferences(profileData, resourceClass), ClassName = resourceClass.Name, EntityName = resourceClass.Name, Constructor = AssembleConstructor(profileData, resourceClass), HasCollections = ((IList)collections).Count > 0, Collections = collections, Identifiers = _resourcePropertyRenderer.AssemblePrimaryKeys(profileData, resourceClass, TemplateContext), NonIdentifiers = _resourcePropertyRenderer.AssembleProperties(resourceClass), InheritedProperties = _resourcePropertyRenderer.AssembleInheritedProperties(profileData, resourceClass), InheritedCollections = _resourceCollectionRenderer.InheritedCollections(profileData, resourceClass, TemplateContext), OnDeserialize = _resourceCollectionRenderer.OnDeserialize(profileData, resourceClass, TemplateContext), Guid = resourceClass.IsAggregateRoot() ? new { ResourceName = resourceClass.Name, GuidConverterTypeName = "GuidConverter" } : ResourceRenderer.DoNotRenderProperty, NavigableOneToOnes = _resourceCollectionRenderer.NavigableOneToOnes(profileData, resourceClass), InheritedNavigableOneToOnes = _resourceCollectionRenderer.InheritedNavigableOneToOnes(profileData, resourceClass), SynchronizationSourceSupport = _resourceCollectionRenderer .SynchronizationSourceSupport(profileData, resourceClass, TemplateContext), Versioning = resourceClass.IsAggregateRoot() ? ResourceRenderer.DoRenderProperty : ResourceRenderer.DoNotRenderProperty, References = _resourceCollectionRenderer.References(profileData, resourceClass, TemplateContext), FQName = resourceClass.FullName, IsAbstract = resourceClass.IsAbstract(), IsAggregateRoot = resourceClass.IsAggregateRoot(), DerivedName = resourceClass.IsDerived ? $@", {EdFiConventions.BuildNamespace( Namespaces.Entities.Common.RelativeNamespace, resourceClass.Entity.BaseEntity.SchemaProperCaseName()) }.I{resourceClass.Entity.BaseEntity.Name}" : ResourceRenderer.DoNotRenderProperty, ParentName = contextualParent?.Name, ParentFieldName = contextualParent?.Name.ToCamelCase(), InterfaceParentFieldName = contextualParent?.Name, ParentNamespacePrefix = parentProperCaseSchemaName == null ? null : $"{Namespaces.Entities.Common.RelativeNamespace}.{parentProperCaseSchemaName}.", IsBaseClassConcrete = resourceClass.Entity != null && resourceClass.Entity.IsDerived && resourceClass.Entity.BaseEntity != null && !resourceClass.Entity.BaseEntity.IsAbstractRequiringNoCompositeId(), DerivedBaseTypeName = resourceClass.IsDerived && resourceClass.Entity != null ? resourceClass.Entity.BaseEntity?.Name : ResourceRenderer.DoNotRenderProperty, FilteredDelegates = _resourceCollectionRenderer.FilteredDelegates(profileData, resourceClass), ShouldRenderValidator = putPostRequestValidator != ResourceRenderer.DoNotRenderProperty, Validator = putPostRequestValidator, IsExtendable = resourceClass.IsExtendable(), IsProfileProject = TemplateContext.IsProfiles, HasSupportedExtensions = profileData.SuppliedResource.Extensions.Any(), SupportedExtensions = profileData.SuppliedResource.Extensions .Select(e => new { ExtensionName = TemplateContext.GetSchemaProperCaseNameForExtension(e) }), IsEdFiResource = resourceClass.IsEdFiResource(), NamespacePrefix = resourceClass.GetNamespacePrefix(), HasDiscriminator = resourceClass.HasDiscriminator(), // Foreign Key Discriminators should not have any profile applied to this, as this data is required for links ResourceReferences = CreateResourceReferences(resourceClass) }); }
protected override object Build() { string ColumnNamesFor(IEnumerable <string> columnNames) => string.Join(", ", columnNames.Select(c => $@"""{c}""")); bool EntityInSchema(Entity e) => TemplateContext.SchemaPhysicalName.Equals(e.FullName.Schema); bool AssociationInSchema(Association a) => TemplateContext.SchemaPhysicalName.Equals(a.FullName.Schema); bool AssociationIsNotOneToOne(Association a) => a.Cardinality != Cardinality.OneToOne && a.Cardinality != Cardinality.OneToOneInheritance && a.Cardinality != Cardinality.OneToOneExtension; DatabaseMetadata DatabaseMetadataForEntity(Entity e) => new DatabaseMetadata { Name = e.Identifier.Name, TableName = e.Name, ColumnNames = ColumnNamesFor(e.Identifier.Properties.Select(p => p.PropertyName)), }; IEnumerable <DatabaseMetadata> DatabaseMetadataForAlternativeIdentities(Entity e) => e.AlternateIdentifiers.Select( ai => new DatabaseMetadata { Name = ai.Name, TableName = e.Name, ColumnNames = ColumnNamesFor(ai.Properties.Select(p => p.PropertyName)), }); DatabaseMetadata DatabaseMetadataForAssociation(Association a) => new DatabaseMetadata { Name = a.FullName.Name, TableName = a.SecondaryEntity.Name, ColumnNames = ColumnNamesFor(a.SecondaryEntityAssociationProperties.Select(p => p.PropertyName)), }; var databaseMetadata = new List <DatabaseMetadata>(); var domainModel = TemplateContext.DomainModelProvider.GetDomainModel(); databaseMetadata.AddRange( domainModel.Entities .Where(EntityInSchema) .Select(DatabaseMetadataForEntity)); databaseMetadata.AddRange( domainModel.Entities .Where(EntityInSchema) .SelectMany(DatabaseMetadataForAlternativeIdentities)); databaseMetadata.AddRange( domainModel.Associations .Where(AssociationInSchema) .Where(AssociationIsNotOneToOne) .Select(DatabaseMetadataForAssociation)); return(new { NamespaceName = EdFiConventions.BuildNamespace( Namespaces.CodeGen.ExceptionHandling, TemplateContext.SchemaProperCaseName), IndexMetaData = databaseMetadata.OrderBy(x => x.TableName).ThenBy(x => x.Name) }); }
public override HttpControllerDescriptor SelectController(HttpRequestMessage request) { if (_duplicates.Any()) { throw new HttpResponseException( request.CreateErrorResponse( HttpStatusCode.InternalServerError, $@"Duplicate controllers have been detected. Due to ambiguity, no requests will be served until this is resolved. The following controllers have been detected as duplicates: {string.Join(", ", _duplicates)}")); } IHttpRouteData routeData = request.GetRouteData(); if (routeData == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } string controllerName = GetRouteVariable <string>(routeData, ControllerKey); // schema section of url ie /data/v3/{schema}/{resource} ex: /data/v3/ed-fi/schools string resourceSchema = GetRouteVariable <string>(routeData, ResourceOwnerKey); if (ShouldUseDefaultSelectController(controllerName, resourceSchema)) { // If there's no controller or schema name, defer to the base class for direct route handling // Also if the controller is a composite controller we defer to base class. return(base.SelectController(request)); } string resourceSchemaNamespace = string.Empty; if (controllerName.EqualsIgnoreCase("deletes")) { resourceSchemaNamespace = "EdFi.Ods.ChangeQueries.Controllers"; } else { try { string properCaseName = _schemaNameMapProvider .GetSchemaMapByUriSegment(resourceSchema) .ProperCaseName; // for now the check is including the ignore case due to the way the schema name map provider is implemented // this should be address on the changes in phase 4 where the map provider is using dictionaries. resourceSchemaNamespace = EdFiConventions.BuildNamespace( Namespaces.Api.Controllers, properCaseName, controllerName, !EdFiConventions.ProperCaseName.EqualsIgnoreCase(properCaseName)); } // Quietly ignore any failure to find the schema name, allowing NotFound response logic below to run catch (KeyNotFoundException) {} } // Verify org section matches a known resource owner derived from any assembly implementing ISchemaNameMap if (string.IsNullOrEmpty(resourceSchemaNamespace)) { throw new HttpResponseException( request.CreateErrorResponse( HttpStatusCode.NotFound, "Resource schema value provided in uri does not match any known values.")); } ProfileContentTypeDetails profileContentTypeDetails = null; // http method type determines where the profile specific content type will be sent. if (request.Method == HttpMethod.Get) { profileContentTypeDetails = (from a in request.Headers.Accept where a.MediaType.StartsWith("application/vnd.ed-fi.") let details = a.MediaType.GetContentTypeDetails() select details) .SingleOrDefault(); } else if (request.Method == HttpMethod.Put || request.Method == HttpMethod.Post) { if (request.Content != null) { var contentType = request.Content.Headers.ContentType; // check that there was a content type on the request if (contentType != null) { // check if the content type is a profile specific content type if (contentType.MediaType.StartsWith("application/vnd.ed-fi.")) { // parse the profile specific content type string into the object. profileContentTypeDetails = contentType.MediaType.GetContentTypeDetails(); // Was a profile-specific content type for the controller/resource found and was it parseable? // if it was not parsable but started with "application/vnd.ed-fi." then throw an error if (profileContentTypeDetails == null) { throw new HttpResponseException( BadRequestHttpResponseMessage( request, "Content type not valid on this resource.")); } } } } } HttpControllerDescriptor controllerDescriptor; string key; bool profileControllerNotFound = false; // Was a profile-specific content type for the controller/resource found? if (profileContentTypeDetails != null) { // Ensure that the content type resource matchs requested resource if (!profileContentTypeDetails.Resource .EqualsIgnoreCase(CompositeTermInflector.MakeSingular(controllerName))) { throw new HttpResponseException( BadRequestHttpResponseMessage( request, "The resource is not accessible through the profile specified by the content type.")); } // Ensure that if the method is get that the profile specific content type sent readable if (request.Method == HttpMethod.Get && profileContentTypeDetails.Usage != ContentTypeUsage.Readable) { throw new HttpResponseException( BadRequestHttpResponseMessage( request, "The resource is not accessible through the profile specified by the content type.")); } // Ensure that if the http method is PUT or POST that the profile specific type sent was writable if ((request.Method == HttpMethod.Put || request.Method == HttpMethod.Post) && profileContentTypeDetails.Usage != ContentTypeUsage.Writable) { throw new HttpResponseException( BadRequestHttpResponseMessage( request, "The resource is not accessible through the profile specified by the content type.")); } // Use the profile name as the namespace for controller matching string profileName = profileContentTypeDetails.Profile.Replace('-', '_'); // + "_" + profileContentTypeDetails.Usage; // Find a matching controller. // ex : EdFi.Ods.Api.Services.Controllers.AcademicHonorCategoryTypes.Academic_Week_Readable_Excludes_Optional_References.AcademicHonorCategoryTypes key = string.Format( CultureInfo.InvariantCulture, "{0}.{1}.{2}", resourceSchemaNamespace, profileName, controllerName); if (_controllers.Value.TryGetValue(key, out controllerDescriptor)) { return(controllerDescriptor); } profileControllerNotFound = true; } // Find a matching controller. // ex : EdFi.Ods.Api.Services.Controllers.AcademicHonorCategoryTypes.AcademicHonorCategoryTypes key = string.Format( CultureInfo.InvariantCulture, "{0}.{1}", resourceSchemaNamespace, controllerName); if (_controllers.Value.TryGetValue(key, out controllerDescriptor)) { // If there is a controller, just not with the content type specified, it's a bad request if (profileControllerNotFound) { // If the profile does not exist in this installation of the api throw an error dependent on the http method if (!ProfileExists(profileContentTypeDetails.Profile)) { if (request.Method == HttpMethod.Get) { throw new HttpResponseException(NotAcceptableHttpResponseMessage(request)); } if (request.Method == HttpMethod.Put || request.Method == HttpMethod.Post) { throw new HttpResponseException(UnsupportedMediaTypeHttpResponseMessage(request)); } } // The profile exists but the resource doesnt exist under it throw new HttpResponseException( BadRequestHttpResponseMessage( request, string.Format( "The '{0}' resource is not accessible through the '{1}' profile specified by the content type.", CompositeTermInflector.MakeSingular(controllerName), profileContentTypeDetails.Profile))); } return(controllerDescriptor); } throw new HttpResponseException(HttpStatusCode.NotFound); }