public HttpResponseMessage PostStockQuote(StockQuote stockQuote) { stockQuote.SetIdentifier(Utilities.CreateStockQuoteIdentifier(stockQuote)); StockQuote newStockQuote = stockQuoteStore.Add(stockQuote); //Get realtime stock quote retrieveStockQuoteInfo(newStockQuote); //Update the resource with runtime subject and ServiceProvider URIs newStockQuote.SetAbout(new Uri(ServiceProviderController.About.ToString() + "/" + stockQuote.GetIdentifier())); newStockQuote.SetServiceProvider(ServiceProviderController.ServiceProviderUri); //Create a response containing the new resource + a Location header var response = Request.CreateResponse <StockQuote>(HttpStatusCode.Created, newStockQuote); string uri = Url.Link("DefaultApi", new { id = stockQuote.GetIdentifier() }); response.Headers.Location = new Uri(uri); return(response); }
/// <summary> /// Retrieve and reaturn a single StockQuote resource /// </summary> /// <param name="id"></param> /// <returns></returns> public StockQuote GetStockQuote(string id) { //following will throw an exception if id is bad StockQuote requestedStockQuote = stockQuoteStore.Get(id); //Get realtime stock quote retrieveStockQuoteInfo(requestedStockQuote); //Update the resource with runtime subject and ServiceProvider URIs requestedStockQuote.SetAbout(new Uri(ServiceProviderController.About.ToString() + "/" + requestedStockQuote.GetIdentifier())); requestedStockQuote.SetServiceProvider(ServiceProviderController.ServiceProviderUri); return(requestedStockQuote); }