public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log, [Inject] IApprenticeshipService apprenticeshipService) { string codeFromQuery = req.Query["StandardCode"]; string versionFromQuery = req.Query["Version"]; List <StandardsAndFrameworks> persisted = null; if (string.IsNullOrWhiteSpace(codeFromQuery)) { return(new BadRequestObjectResult($"Empty or missing Standard Code value.")); } if (!int.TryParse(codeFromQuery, out int standardCode)) { return(new BadRequestObjectResult($"Invalid Standard Code value, expected a valid integer")); } if (string.IsNullOrWhiteSpace(versionFromQuery)) { return(new BadRequestObjectResult($"Empty or missing Version value.")); } if (!int.TryParse(versionFromQuery, out int standardVersion)) { return(new BadRequestObjectResult($"Invalid Version value, expected a valid integer")); } try { persisted = await apprenticeshipService.GetStandardByCode(standardCode, standardVersion); if (persisted == null) { return(new NotFoundObjectResult(standardCode)); } return(new OkObjectResult(persisted)); } catch (Exception e) { return(new InternalServerErrorObjectResult(e)); } }