public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { try { var partition = req.Query["partition"]; var service = new EntriesBL(); var config = await service.GetEntryConfig(partition); if (config == null) { return(new BadRequestResult()); } var answers = await service.GetAnswerEntriesForPartition(partition); var scores = service.GetScoredResults(answers); return(new OkObjectResult(new { config, scores, answers })); } catch (Exception ex) { log.LogError(ex.Message, ex); return(new BadRequestObjectResult(ex.Message)); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { try { var partition = req.Query["partition"]; var service = new EntriesBL(); var config = await service.GetEntryConfig(partition); if (config == null) { return(new BadRequestResult()); } string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var model = JsonConvert.DeserializeObject <AnswerAM>(requestBody); if (!model.IsValid) { return(new BadRequestObjectResult("Model is invalid! Name or dates missing.")); } var entity = new AnswerEntity(partition, model.Name) { Name = model.Name, AdditionalMessage = model.AdditionalMessage, SelectedDatesString = string.Join(',', model.SelectedDates.Select(sd => sd.ToString("yyyy-MM-dd"))) }; var table = await StorageService.GetStorageTableReference(); await table.ExecuteAsync(TableOperation.Insert(entity)); if (!string.IsNullOrEmpty(config.WebHookUrl)) { using (var client = new HttpClient()) { await client.PostAsync(config.WebHookUrl, null); } } return(new OkObjectResult(entity)); } catch (Exception ex) { log.LogError(ex.Message, ex); return(new BadRequestObjectResult(ex.Message)); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { try { var partition = req.Query["partition"]; var service = new EntriesBL(); var model = await service.GetAnswerEntriesForPartition(partition); return(new OkObjectResult(model)); } catch (Exception ex) { log.LogError(ex.Message, ex); return(new BadRequestObjectResult(ex.Message)); } }