Exemplo n.º 1
0
        public IHttpActionResult DeleteSample(string id)
        {
            // Create a retrieve operation that takes a sample entity.
            TableOperation retrieveOperation = TableOperation.Retrieve <SampleEntity>(partitionName, id);

            // Execute the retrieve operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            if (retrievedResult.Result == null)
            {
                return(NotFound());
            }
            else
            {
                // GET THE RESULT TO DELETE
                SampleEntity deleteEntity = (SampleEntity)retrievedResult.Result;

                // REMOVE ANY RELATED MP3 IN BLOB STORAGE
                Mp3sController mp3 = new Mp3sController();
                mp3.Delete(deleteEntity);


                // CREATE THE DELETE OPERATION
                TableOperation deleteOperation = TableOperation.Delete(deleteEntity);

                // EXECUTE THE DELETE OPERATION
                table.Execute(deleteOperation);

                // JUST RETURN A 204
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult PutSample(string id, Sample sample)
        {
            // CHECK TO MAKE SURE THERE IS A SAMPLE SUPPLIED
            if (sample == null)
            {
                return(BadRequest("You must supply a sample to update"));
            }

            // CHECK TO MAKE SURE ID MATCHES THE SAMPLE
            if (id != sample.SampleID)
            {
                return(BadRequest("Your ID's do not match"));
            }

            // Create a retrieve operation that takes a sample entity.
            TableOperation retrieveOperation = TableOperation.Retrieve <SampleEntity>(partitionName, id);

            // Execute the operation.
            TableResult retrievedResult = table.Execute(retrieveOperation);

            // IF THERE IS NO ENTITY, RETURN NOT FOUND
            if (retrievedResult.Result == null)
            {
                return(NotFound());
            }


            // Assign the result to a SampleEntity object.
            SampleEntity updateEntity = (SampleEntity)retrievedResult.Result;

            // Delete any existing blobs in storage
            Mp3sController mp3s = new Mp3sController();

            mp3s.Delete(updateEntity);

            // Create the updates on the object
            updateEntity.Title         = sample.Title;
            updateEntity.Artist        = sample.Artist;
            updateEntity.Mp3Blob       = null;
            updateEntity.SampleMp3Blob = null;
            updateEntity.SampleMp3Url  = null;

            // CREATE THE UPDATE OPERATION
            var updateOperation = TableOperation.InsertOrReplace(updateEntity);

            // EXECUTE THE UPDATE OPERATION
            table.Execute(updateOperation);

            return(StatusCode(HttpStatusCode.NoContent));
        }