using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using System.Collections.Generic; using System.Net; using TEAMModelOS.SDK.DI; using TEAMModelOS.SDK.Models; using TEAMModelOS.SDK.Extension; using System.Text.Json; namespace FunctionApp1 { public class Function1 { private readonly AzureCosmosFactory _azureCosmos; public Function1(AzureCosmosFactory azureCosmos) { _azureCosmos = azureCosmos; } [Function("Common")] public async Task Common([CosmosDBTriggerAttribute( databaseName: "TEAMModelOS", containerName: "Common", Connection = "Azure:Cosmos:ConnectionString", LeaseContainerName = "leases", LeaseContainerPrefix = "TEAMModelOS", CreateLeaseContainerIfNotExists =true)]string data, ILogger log) { try { var teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync("1595321354", new Azure.Cosmos.PartitionKey("Base")); Console.WriteLine(teacher.ToJsonString()); Console.WriteLine(data); } catch (Exception ex) { Console.WriteLine($"{ex.Message}{ex.StackTrace}"); } } [Function("GroupChange")] public async Task GroupChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "group-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg) { var teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync("1595321354", new Azure.Cosmos.PartitionKey("Base")); } [Function("Function1")] public async Task Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext context) { string name = req.ReadAsString(); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; string responseMessage = string.IsNullOrEmpty(name) ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." : $"Hello, {name}. This HTTP triggered function executed successfully."; var response= req.CreateResponse(HttpStatusCode.OK); //response.Headers.Add("Content-Type", "application/json; charset=utf-8"); Teacher teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync("1595321354", new Azure.Cosmos.PartitionKey("Base")); await response.WriteAsJsonAsync(teacher); return response; } } }