public async static Task <IActionResult> CreateTicket( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, TraceWriter log, ExecutionContext context) { log.Info($"C# HTTP trigger function processed a request {nameof(CreateTicket)}"); var config = Config.Load(context); Ticket data = JsonConvert.DeserializeObject <Ticket>(GetRequestBody(req)); var ticketsColletion = MongoConnection.Load(config).GetCollection <Ticket>("tickets"); await ticketsColletion.InsertOneAsync(data); return(new JsonResult(data, JsonSettings)); }
public async static Task <IActionResult> UpdateTicket( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, TraceWriter log, ExecutionContext context) { log.Info($"C# HTTP trigger function processed a request {nameof(UpdateTicket)}"); var config = Config.Load(context); Ticket ticket = JsonConvert.DeserializeObject <Ticket>(GetRequestBody(req)); var updateResult = await MongoConnection.Load(config) .GetCollection <Ticket>("tickets") .ReplaceOneAsync(item => item.Id == ticket.Id, ticket); //, new UpdateOptions {IsUpsert = true} return(new OkObjectResult(updateResult)); }
public async static Task <IActionResult> LoadTickets( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext context) { log.Info($"C# HTTP trigger function processed a request {nameof(LoadTickets)}"); var config = Config.Load(context); string name = req.Query["name"]; // string requestBody = new StreamReader(req.Body).ReadToEnd(); // dynamic data = JsonConvert.DeserializeObject(requestBody); // name = name ?? data?.name; var tickets = await MongoConnection.Load(config) .GetCollection <Ticket>("tickets") .Find(_ => true) .SortByDescending(t => t.DateSent) .ToListAsync(); return(new JsonResult(tickets, JsonSettings)); }