using Competition.Common.Util; using CompetitionAPI.api.back; using CompetitionAPI.Util; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace CompetitionAPI.Controllers.back.study { [Route("api/[controller]")] [ApiController] public class CommentController : Controller { Competition.Mysql.BLL.pow_study_record record_bll = new Competition.Mysql.BLL.pow_study_record(); public CommentController() { } /// /// 评语接口 /// /// 请求参数 /// [Authorize] [HttpPost] [APIFilter] public JsonResult Index([FromBody] CommentRequest req) { try { if (string.IsNullOrWhiteSpace(req.UserId)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "被评语用户id不能为空")); } if (string.IsNullOrWhiteSpace(req.StudyId)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "学习id不能为空")); } if (string.IsNullOrWhiteSpace(req.RealName)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "被评语用户姓名不能为空")); } //if (string.IsNullOrWhiteSpace(req.RecordId)) //{ // return Json(Tool.GetJsonWithCode(APICode.Fail, "记录id不能为空")); //} if (string.IsNullOrWhiteSpace(req.Comment)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "评语内容不能为空")); } if (string.IsNullOrWhiteSpace(req.ReviewerId)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "评语人用户id不能为空")); } if (string.IsNullOrWhiteSpace(req.Reviewer)) { return Json(Tool.GetJsonWithCode(APICode.Fail, "评语人姓名不能为空")); } var model = record_bll.GetModelList(string.Format(" StudyId='{0}' and UserId='{1}' ", req.StudyId, req.UserId)).FirstOrDefault(); if (model == null) { model = new Competition.Mysql.Model.pow_study_record(); model.RecordId = Guid.NewGuid().ToString("N"); model.UserId = req.UserId; model.StudyId = req.StudyId; model.RealName = req.RealName; model.Schedule = "0"; model.Comment = req.Comment; model.ReviewerId = req.ReviewerId; model.Reviewer = req.Reviewer; model.ReviewerTime = DateTime.Now; model.CreateTime = DateTime.Now; if (record_bll.Add(model)) { return Json(Tool.GetJsonWithCode(APICode.Success, "评语成功")); } else { return Json(Tool.GetJsonWithCode(APICode.Fail, "评语失败")); } } else { model.Comment = req.Comment; model.ReviewerId = req.ReviewerId; model.Reviewer = req.Reviewer; model.ReviewerTime = DateTime.Now; if (record_bll.Update(model)) { return Json(Tool.GetJsonWithCode(APICode.Success, "评语成功")); } else { return Json(Tool.GetJsonWithCode(APICode.Fail, "评语失败")); } } } catch (Exception ex) { LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace); return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。")); } } } }