using HaBookCms.AzureCosmos.CosmosDB.Interfaces; using HaBookCms.Core.Models.Contest; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace HaBookCms.AzureCosmosDBTest.Controllers { [Route("api/[controller]")] [ApiController] public class CosmosDBController: ControllerBase { private IAzureCosmosDBRepository _azureCosmosDB; public CosmosDBController(IAzureCosmosDBRepository azureCosmosDB) { _azureCosmosDB = azureCosmosDB; } [HttpGet("save")] [EnableCors("any")] [AllowAnonymous] public async Task SaveActivity() { Console.WriteLine(); BaseActivty activty = new BaseActivty { Id = "activity.111221", Title = "报名活动", Introduce = "本次活动纯属娱乐", ActivityLink = "http://www.runoob.com/csharp/csharp-methods.html", state = "1", Models = new BaseActivty.Model[] { new BaseActivty.Model { ModelId="1", ModelName="报名", ModelStartTime="2019-01-01", ModelEndTime = "2019-01-20" }, new BaseActivty.Model { ModelId="2", ModelName="上传附件", ModelStartTime="2019-01-01", ModelEndTime = "2019-01-20" }, new BaseActivty.Model { ModelId="3", ModelName="专家评审", ModelStartTime="2019-01-10", ModelEndTime = "2019-01-20" }, new BaseActivty.Model { ModelId="4", ModelName="成绩公示", ModelStartTime="2019-01-18", ModelEndTime = "2019-01-20" } }, Children = new BaseActivty.Parts[] { new BaseActivty.Parts{ PartId = "label.1", PartlLabel = "选择器", PartFiled = "sex", PartType = "select" }, new BaseActivty.Parts{ PartId = "label.2", PartlLabel = "单选按钮", PartFiled = "education", PartType = "checkboks" }, new BaseActivty.Parts{ PartId = "label.3", PartlLabel = "文本框", PartFiled = "name", PartType = "input" } } }; await _azureCosmosDB.Save(activty); return activty.Id; } [HttpGet("find")] [EnableCors("any")] [AllowAnonymous] public object ExecuteSimpleQuery() { //_azureCosmosDB.FindLinq( Queryable.SingleOrDefault); // Here we find the Andersen family via its LastName //return await _azureCosmosDB.FindAll(); string sql = "select * from c "; return _azureCosmosDB.FindSQL(sql); // The query is executed synchronously here, but can also be executed asynchronously via the IDocumentQuery interface //Console.WriteLine("Running LINQ query..."); } } }