123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.Context.Exception;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.Service.Models;
- using System.Text.Json;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- namespace TEAMModelOS.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class CommentController :BaseController
- {
- private readonly AzureCosmosFactory _azureCosmos;
- public CommentController(AzureCosmosFactory azureCosmos)
- {
- _azureCosmos = azureCosmos;
- }
- /// <summary>
- /// 添加教师评语快捷回复
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("addComment")]
- public async Task<BaseResponse> AddComment(CommentsDto request)
- {
- var id = "Comment-" + request.TEAMModelId.Replace("#", "");
- ResponseBuilder builder = ResponseBuilder.custom();
- List<Comment> Comment = await _azureCosmos.FindByDict<Comment>(new Dictionary<string, object> { { "code", request.TEAMModelId }, { "id", id } });
- Comment comment = new Comment();
- if (Comment.IsEmpty())
- {
- comment.id = id;
- comment.code = request.TEAMModelId;
- comment.comment.Add(request.comment);
- Comment.Add(comment);
- }
- else {
- comment = Comment[0];
- comment.comment.Add(request.comment);
- }
- builder.Data(await _azureCosmos.SaveOrUpdate(comment));
- return builder.build();
- }
- /// <summary>
- /// 查询教师评语罐头
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("findComment")]
- public async Task<BaseResponse> findComment(JsonElement request)
- {
- // request.TryAdd("PartitionKey", request.lang);
- ResponseBuilder builder = ResponseBuilder.custom();
- List<Comment> data = new List<Comment>();
- if (StringHelper.getKeyCount(request) > 0)
- {
- data = await _azureCosmos.FindByDict<Comment>(request);
- }
- else
- {
- return builder.Error(ResponseCode.PARAMS_ERROR, "参数异常!").build();
- }
- return builder.Data(data).build();
- }
- /// <summary>
- /// 更新保存教师评语罐头,如果评语列表为空则删除
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("upsertComment")]
- public async Task<BaseResponse> UpsertComment(Comment request)
- {
- // request.TryAdd("PartitionKey", request.lang);
- ResponseBuilder builder = ResponseBuilder.custom();
- Comment comment = null;
- if (request.comment.Count > 0)
- {
- if (string.IsNullOrEmpty(request.id)) {
- request.id = "Comment-" + request.code.Replace("#", "");
- }
- comment = await _azureCosmos.SaveOrUpdate<Comment>(request);
- }
- else {
- if (!string.IsNullOrEmpty(request.id))
- {
- IdPk idPk = await _azureCosmos.DeleteAsync<Comment>(request.id, request.code);
- }
-
- }
- return builder.Data(comment).build();
- }
-
- }
- }
|