Beispiel #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "Speakers")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Start Add Speakers");

            try
            {
                var body = await req.GetBodyAsync <List <SpeakerRequest> >();

                if (!body.IsValid)
                {
                    log.LogError($"Error - adding speakers"); return(new BadRequestObjectResult(new { Message = string.Join(", ", body.ValidationResults.Select(s => s.ErrorMessage).ToArray()) }));

                    return(new BadRequestResult());
                }

                foreach (var item in body.Value)
                {
                    log.LogInformation(JsonConvert.SerializeObject(item));
                }

                await _speakerService.AddSpeakers(body.Value);
            }
            catch (Exception ex)
            {
                log.LogError($"Error - adding speakers"); return(new BadRequestObjectResult(new { Message = ex.Message + " - " + ex.StackTrace }));

                return(new BadRequestResult());
            }

            return(new OkResult());
        }