123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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<object> 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<BaseActivty>(activty);
- return activty.Id;
- }
- [HttpGet("find")]
- [EnableCors("any")]
- [AllowAnonymous]
- public object ExecuteSimpleQuery()
- {
- //_azureCosmosDB.FindLinq<BaseActivty>( Queryable.SingleOrDefault);
- // Here we find the Andersen family via its LastName
- //return await _azureCosmosDB.FindAll<BaseActivty>();
- string sql = "select * from c ";
- return _azureCosmosDB.FindSQL<BaseActivty>(sql);
- // The query is executed synchronously here, but can also be executed asynchronously via the IDocumentQuery<T> interface
- //Console.WriteLine("Running LINQ query...");
- }
- }
- }
|