public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { // Get query terms char track = '@'; // we will never see this in a nat message so we use it as our default bool si = false; // Check track arg if (!string.IsNullOrWhiteSpace(req.Query["id"]) && req.Query["id"].Count == 1) { track = req.Query["id"].ToString()[0]; } // Check SI if (!string.IsNullOrWhiteSpace(req.Query["si"]) && bool.TryParse(req.Query["si"], out var res)) { if (res || !res) { si = res; } } // Get the tracks List <Track> parsedTracks = TrackUtils.ParseTracks(si); Track returnObj = parsedTracks.Where(t => t.Id == track).FirstOrDefault(); // Error if not found if (returnObj == null) { return(new NotFoundObjectResult("The requested track was not found in the message.")); } // Return the result if it is found return(new OkObjectResult(returnObj)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { // Get query terms bool si = false; bool eventTracks = false; bool concorde = false; // Check SI if (!string.IsNullOrWhiteSpace(req.Query["si"]) && bool.TryParse(req.Query["si"], out var res)) { if (res || !res) { si = res; } } // Check event tracks if (string.IsNullOrWhiteSpace(req.Query["concorde"]) && !string.IsNullOrWhiteSpace(req.Query["event"]) && bool.TryParse(req.Query["event"], out var res1)) { if (res1 || !res1) { eventTracks = res1; } } // Check SI if (string.IsNullOrWhiteSpace(req.Query["event"]) && !string.IsNullOrWhiteSpace(req.Query["concorde"]) && bool.TryParse(req.Query["concorde"], out var res2)) { if (res2 || !res2) { concorde = res2; } } // Get the tracks List <Track> parsedTracks = new List <Track>(); // Return the results if (eventTracks) { // Event path string path = "https://ganderoceanicoca.ams3.digitaloceanspaces.com/resources/data/eventTracks.json"; // Return using (WebClient client = new WebClient()) { return(new OkObjectResult(client.DownloadString(path))); } } else if (concorde) { // Concorde track path string path = "https://ganderoceanicoca.ams3.digitaloceanspaces.com/resources/data/concordeTracks.json"; // Return using (WebClient client = new WebClient()) { return(new OkObjectResult(client.DownloadString(path))); } } else { // Assign and return parsedTracks = TrackUtils.ParseTracks(si); return(new OkObjectResult(parsedTracks)); } }