Created
September 29, 2016 22:23
-
-
Save jplane/73b964dcaf79e63482bce67016b58b10 to your computer and use it in GitHub Desktop.
Web API controller to query IoT device metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapController : ApiController | |
{ | |
[Route("api/map/{id}")] | |
public object Get(int id) | |
{ | |
var uri = new Uri(ConfigurationManager.AppSettings["docdbUri"]); | |
var key = ConfigurationManager.AppSettings["docdbKey"]; | |
var dbName = ConfigurationManager.AppSettings["docdbDatabaseName"]; | |
var collName = ConfigurationManager.AppSettings["docdbCollName"]; | |
var client = new DocumentClient(uri, key); | |
var query = client.CreateDocumentQuery<BusInfo>(UriFactory.CreateDocumentCollectionUri(dbName, collName), | |
new FeedOptions { MaxItemCount = 1 }) | |
.Where(bi => bi.VehicleId == id); | |
var result = query.AsEnumerable().FirstOrDefault(); | |
return result != null | |
? new | |
{ | |
tripid = result.TripId, | |
route = result.RouteShortName, | |
vehicleid = result.VehicleId, | |
timeliness = result.Timeliness.ToString() | |
} | |
: null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment