public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
                                                     ILogger log,
                                                     [Inject] IApprenticeshipService apprenticeshipService)
        {
            List <Apprenticeship> persisted = null;


            try
            {
                persisted = (List <Apprenticeship>) await apprenticeshipService.GetUpdatedApprenticeships();

                if (persisted == null)
                {
                    return(new EmptyResult());
                }
                var listOfProviderUKPRN = persisted.Select(x => x.ProviderUKPRN.ToString())
                                          .Distinct()
                                          .ToList();
                List <Apprenticeship> totalList = new List <Apprenticeship>();
                foreach (var ukprn in listOfProviderUKPRN)
                {
                    var results = apprenticeshipService.GetApprenticeshipByUKPRN(int.Parse(ukprn)).Result;
                    if (results.Any())
                    {
                        totalList.AddRange((List <Apprenticeship>)results);
                    }
                }
                var providers = apprenticeshipService.ApprenticeshipsToTribalProviders(totalList);
                return(new OkObjectResult(providers));
            }
            catch (Exception e)
            {
                return(new InternalServerErrorObjectResult(e));
            }
        }
コード例 #2
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
                                                     ILogger log,
                                                     [Inject] IApprenticeshipService apprenticeshipService)
        {
            string fromQuery = req.Query["UKPRN"];
            List <Apprenticeship> persisted = null;

            if (string.IsNullOrWhiteSpace(fromQuery))
            {
                return(new BadRequestObjectResult($"Empty or missing UKPRN value."));
            }

            if (!int.TryParse(fromQuery, out int UKPRN))
            {
                return(new BadRequestObjectResult($"Invalid UKPRN value, expected a valid integer"));
            }

            try
            {
                persisted = (List <Apprenticeship>) await apprenticeshipService.GetApprenticeshipByUKPRN(UKPRN);

                if (persisted == null)
                {
                    return(new NotFoundObjectResult(UKPRN));
                }

                var tribalProviders = (List <TribalProvider>)apprenticeshipService.ApprenticeshipsToTribalProviders(persisted);
                return(new OkObjectResult(tribalProviders));
            }
            catch (Exception e)
            {
                return(new InternalServerErrorObjectResult(e));
            }
        }
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
                                                     ILogger log,
                                                     [Inject] IApprenticeshipService apprenticeshipService)
        {
            string fromQuery = req.Query["UKPRN"];
            List <Apprenticeship> apprenticeships = null;

            try
            {
                apprenticeships = (List <Apprenticeship>) await apprenticeshipService.GetApprenticeshipCollection();

                if (apprenticeships == null)
                {
                    return(new NotFoundObjectResult("Could not retrieve apprenticeships"));
                }

                var tribalProviders = (List <TribalProvider>)apprenticeshipService.ApprenticeshipsToTribalProviders(apprenticeships);
                return(new OkObjectResult(tribalProviders));
            }
            catch (Exception e)
            {
                return(new InternalServerErrorObjectResult(e));
            }
        }