Пример #1
0
        public Stream Delete(string type, string id)
        {
            IResourceHandler handler = _registry.GetHandler(type);

            if (handler == null)
            {
                return(ErrorMessage(HttpStatusCode.NotImplemented, String.Format("Delete resource of type {0} not implemented.", type)));
            }
            WebOperationContext.Current.OutgoingResponse.StatusCode = handler.Delete(id);
            return(new MemoryStream(Encoding.UTF8.GetBytes(String.Empty)));
        }
Пример #2
0
        /// <summary>
        /// Handles DELETE by removing a resource
        /// </summary>
        /// <param name="request"></param>
        /// <param name="resourceHandler"></param>
        /// <param name="resourceDescriptor"></param>
        /// <returns></returns>
        private async Task HandleDelete(IRequest request, IResourceHandler resourceHandler, ResourceDescriptor resourceDescriptor)
        {
            try
            {
                // get the resource to ensure it exists
                var existing = await resourceHandler.Get(resourceDescriptor);

                if (existing == null)
                {
                    request.Response.WithStatus(HttpStatusCode.NotFound);
                    return;
                }

                // delete the resource using the handler
                await resourceHandler.Delete(resourceDescriptor);

                // return OK to indicate the resource was successfully deleted
                request.Response.WithStatus(HttpStatusCode.OK);
            }
            catch (Exception e)
            {
                request.Response.WithStatus(HttpStatusCode.InternalServerError).WithPlainTextBody(e.ToString());
            }
        }