/// <summary> /// Handles POST requests that create new entities in the entity set. /// </summary> /// <param name="entity">The entity to insert into the entity set.</param> /// <returns>The response message to send back to the client.</returns> public virtual HttpResponseMessage Post([FromBody] TEntity entity) { TEntity createdEntity = CreateEntity(entity); TKey entityKey = GetKey(entity); return(EntitySetControllerHelpers.PostResponse(this, createdEntity, entityKey)); }
public void PostResponse_Throws_IfODataPathMissing() { ApiController controller = new Mock <ApiController>().Object; var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Customers"); controller.Configuration = new HttpConfiguration(); controller.Request = request; Assert.Throws <InvalidOperationException>( () => EntitySetControllerHelpers.PostResponse <Customer, int>(controller, new Customer(), 5), "A Location header could not be generated because the request does not have an associated OData path."); }
public void PostResponse_Throws_IfODataPathDoesNotStartWithEntitySet() { ApiController controller = new Mock <ApiController>().Object; var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Customers"); controller.Configuration = new HttpConfiguration(); request.SetODataPath(new ODataPath(new MetadataPathSegment())); controller.Request = request; Assert.Throws <InvalidOperationException>( () => EntitySetControllerHelpers.PostResponse <Customer, int>(controller, new Customer(), 5), "A Location header could not be generated because the request's OData path does not start with an entity set path segment."); }
/// <summary> /// This method should be overridden to create a new entity in the entity set. /// </summary> /// <param name="entity">The entity to add to the entity set.</param> /// <returns>A <see cref="Task"/> that contains the created entity when it completes.</returns> protected internal virtual Task <TEntity> CreateEntityAsync(TEntity entity) { throw EntitySetControllerHelpers.CreateEntityNotImplementedResponse(Request); }
/// <summary> /// This method should be overridden to retrieve an entity by key from the entity set. /// </summary> /// <param name="key">The entity key of the entity to retrieve.</param> /// <returns>A <see cref="Task"/> that contains the retrieved entity when it completes, or <c>null</c> if an entity with the specified entity key cannot be found in the entity set.</returns> protected internal virtual Task <TEntity> GetEntityByKeyAsync(TKey key) { throw EntitySetControllerHelpers.GetEntityByKeyNotImplementedResponse(Request); }
/// <summary> /// This method should be overridden to get the entity key of the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns>The entity key value</returns> protected internal virtual TKey GetKey(TEntity entity) { throw EntitySetControllerHelpers.GetKeyNotImplementedResponse(Request); }
public virtual Task <HttpResponseMessage> HandleUnmappedRequest(ODataPath odataPath) { throw EntitySetControllerHelpers.UnmappedRequestResponse(Request, odataPath); }
public virtual IQueryable <TEntity> Get() { throw EntitySetControllerHelpers.GetNotImplementedResponse(Request); }
/// <summary> /// Handles POST requests that create new entities in the entity set. /// </summary> /// <param name="entity">The entity to insert into the entity set.</param> /// <returns>A <see cref="Task"/> that contains the response message to send back to the client when it completes.</returns> public virtual async Task <HttpResponseMessage> Post([FromBody] TEntity entity) { TEntity createdEntity = await CreateEntityAsync(entity); return(EntitySetControllerHelpers.PostResponse <TEntity, TKey>(this, createdEntity, GetKey(createdEntity))); }
public virtual Task <IEnumerable <TEntity> > Get() { throw EntitySetControllerHelpers.GetNotImplementedResponse(Request); }
public virtual async Task <HttpResponseMessage> Patch([FromODataUri] TKey key, Delta <TEntity> patch) { TEntity patchedEntity = await PatchEntityAsync(key, patch); return(EntitySetControllerHelpers.PatchResponse <TEntity>(Request, patchedEntity)); }
/// <summary> /// Handles PUT requests that attempt to replace a single entity in the entity set. /// </summary> /// <param name="key">The entity key of the entity to replace.</param> /// <param name="update">The updated entity.</param> /// <returns>The response message to send back to the client.</returns> public virtual HttpResponseMessage Put([FromODataUri] TKey key, [FromBody] TEntity update) { TEntity updatedEntity = UpdateEntity(key, update); return(EntitySetControllerHelpers.PutResponse(Request, updatedEntity)); }
public virtual HttpResponseMessage Get([FromODataUri] TKey key) { TEntity entity = GetEntityByKey(key); return(EntitySetControllerHelpers.GetByKeyResponse(Request, entity)); }
/// <summary> /// This method should be overridden to update an existing entity in the entity set. /// </summary> /// <param name="key">The entity key of the entity to update.</param> /// <param name="update">The updated entity.</param> /// <returns>A <see cref="Task"/> that contains the updated entity when it completes.</returns> protected internal virtual Task <TEntity> UpdateEntityAsync(TKey key, TEntity update) { throw EntitySetControllerHelpers.UpdateEntityNotImplementedResponse(Request); }
/// <summary> /// This method should be overridden to handles DELETE requests for deleting existing entities from the entity set. /// </summary> /// <param name="key">The entity key of the entity to delete.</param> /// <returns>A <see cref="Task"/> that completes when the entity has been successfully deleted.</returns> public virtual Task Delete([FromODataUri] TKey key) { throw EntitySetControllerHelpers.DeleteEntityNotImplementedResponse(Request); }
/// <summary> /// This method should be overridden to apply a partial update to an existing entity in the entity set. /// </summary> /// <param name="key">The entity key of the entity to update.</param> /// <param name="patch">The patch representing the partial update.</param> /// <returns>A <see cref="Task"/> that contains the updated entity when it completes.</returns> protected internal virtual Task <TEntity> PatchEntityAsync(TKey key, Delta <TEntity> patch) { throw EntitySetControllerHelpers.PatchEntityNotImplementedResponse(Request); }
public virtual Task CreateLink([FromODataUri] TKey key, string navigationProperty, [FromBody] Uri link) { throw EntitySetControllerHelpers.CreateLinkNotImplementedResponse(Request, navigationProperty); }
public virtual async Task <HttpResponseMessage> Get([FromODataUri] TKey key) { TEntity entity = await GetEntityByKeyAsync(key); return(EntitySetControllerHelpers.GetByKeyResponse <TEntity>(Request, entity)); }
/// <summary> /// This method should be overridden to handle DELETE requests that attempt to break a relationship between two entities. /// </summary> /// <param name="key">The key of the entity with the navigation property.</param> /// <param name="relatedKey">The key of the related entity.</param> /// <param name="navigationProperty">The name of the navigation property.</param> /// <returns>A <see cref="Task"/> that completes when the link has been successfully deleted.</returns> public virtual Task DeleteLink([FromODataUri] TKey key, string relatedKey, string navigationProperty) { throw EntitySetControllerHelpers.DeleteLinkNotImplementedResponse(Request, navigationProperty); }
/// <summary> /// Handles PUT requests that attempt to replace a single entity in the entity set. /// </summary> /// <param name="key">The entity key of the entity to replace.</param> /// <param name="update">The updated entity.</param> /// <returns>A <see cref="Task"/> that contains the response message to send back to the client when it completes.</returns> public virtual async Task <HttpResponseMessage> Put([FromODataUri] TKey key, [FromBody] TEntity update) { TEntity updatedEntity = await UpdateEntityAsync(key, update); return(EntitySetControllerHelpers.PutResponse <TEntity>(Request, updatedEntity)); }
public virtual HttpResponseMessage Patch([FromODataUri] TKey key, Delta <TEntity> patch) { TEntity patchedEntity = PatchEntity(key, patch); return(EntitySetControllerHelpers.PatchResponse(Request, patchedEntity)); }