Esempio n. 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log,
            [Inject] IApprenticeshipService apprenticeshipService)
        {
            string         fromQuery = req.Query["id"];
            Apprenticeship persisted = null;

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

            if (!Guid.TryParse(fromQuery, out Guid id))
            {
                return(new BadRequestObjectResult($"Invalid id value. Expected a non-empty valid {nameof(Guid)}"));
            }

            try
            {
                persisted = (Apprenticeship)await apprenticeshipService.GetApprenticeshipById(id);

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

                return(new OkObjectResult(persisted));
            }
            catch (Exception e)
            {
                return(new InternalServerErrorObjectResult(e));
            }
        }