public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log) { int exportedCount = 0; log.LogInformation("Finding license plate data to export"); var databaseMethods = new DatabaseMethods(log); var licensePlates = databaseMethods.GetLicensePlatesToExport(); if (licensePlates.Any()) { log.LogInformation($"Retrieved {licensePlates.Count} license plates"); var fileMethods = new FileMethods(log); var uploaded = await fileMethods.GenerateAndSaveCsv(licensePlates); if (uploaded) { await databaseMethods.MarkLicensePlatesAsExported(licensePlates); exportedCount = licensePlates.Count; log.LogInformation("Finished updating the license plates"); } else { log.LogInformation( "Export file could not be uploaded. Skipping database update that marks the documents as exported."); } log.LogInformation($"Exported {exportedCount} license plates"); } else { log.LogWarning("No license plates to export"); } if (exportedCount == 0) { return(new NoContentResult()); } else { return(new OkObjectResult($"Exported {exportedCount} license plates")); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { int exportedCount = 0; log.Info("Finding license plate data to export"); var databaseMethods = new DatabaseMethods(log); var licensePlates = databaseMethods.GetLicensePlatesToExport(); if (licensePlates.Any()) { log.Info($"Retrieved {licensePlates.Count} license plates"); var fileMethods = new FileMethods(log); var uploaded = await fileMethods.GenerateAndSaveCsv(licensePlates); if (uploaded) { await databaseMethods.MarkLicensePlatesAsExported(licensePlates); exportedCount = licensePlates.Count; log.Info("Finished updating the license plates"); } else { log.Info( "Export file could not be uploaded. Skipping database update that marks the documents as exported."); } log.Info($"Exported {exportedCount} license plates"); } else { log.Info("No license plates to export"); } return(exportedCount == 0 ? req.CreateResponse(HttpStatusCode.NoContent) : req.CreateResponse(HttpStatusCode.OK, $"Exported {exportedCount} license plates")); }