using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Cosmos; using System.Text.Json; namespace HTEXCosmosDB.Controllers { [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [Route("index")] [ApiController] public class IndexController: ControllerBase { private readonly AzureCosmosFactory _azureCosmosFactory; public IndexController( AzureCosmosFactory azureCosmosFactory ) { _azureCosmosFactory = azureCosmosFactory; } [HttpPost("message")] public async Task Message(JsonElement dto) { List teachers = new List();// where c.id in( '1595321354222','1607409409') await foreach (var item in _azureCosmosFactory.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher"). GetItemQueryIteratorSql(queryText: "select value c from c", requestOptions: new Microsoft.Azure.Cosmos.QueryRequestOptions() { PartitionKey= new Microsoft.Azure.Cosmos.PartitionKey("Base") })) { teachers.Add(item); } List elements = new List(); await foreach (var item in _azureCosmosFactory.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher"). GetItemQueryStreamIteratorSql(queryText: "select value c from c where c.id in( '1595321354222','1607409409222')", requestOptions: new Microsoft.Azure.Cosmos.QueryRequestOptions() { PartitionKey= new Microsoft.Azure.Cosmos.PartitionKey("Base") })) { var json = await JsonDocument.ParseAsync(item.Content); if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0) { foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray()) { elements.Add(obj); } } } return Ok(new { response = teachers,elements }); } } public class Teacher { public string id { get; set;} public string name { get; set; } public string code { get; set; } public string pk { get; set; } } }