using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class SchoolMorningMeetLogController : BaseController { public SchoolMorningMeetLogController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 商学院-每日晨会确认加入 [Authorize] public JsonResult Add(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = AddDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson AddDo(string value) { JsonData data = JsonMapper.ToObject(value); int MeetId = int.Parse(function.CheckInt(data["MeetId"].ToString())); //晨会 int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 Dictionary Obj = new Dictionary(); SchoolMorningMeetLog query = maindb.SchoolMorningMeetLog.Add(new SchoolMorningMeetLog() { CreateDate = DateTime.Now, //创建时间 MeetId = MeetId, //晨会 UserId = UserId, //创客 }).Entity; maindb.SaveChanges(); Obj.Add("Id", query.Id); //Id return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 商学院-每日晨会次数添加 [Authorize] public JsonResult AddTimes(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = AddTimesDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson AddTimesDo(string value) { JsonData data = JsonMapper.ToObject(value); int ParentId = int.Parse(function.CheckInt(data["ParentId"].ToString())); //Id int Kind = int.Parse(function.CheckInt(data["Kind"].ToString())); //类型(1 晨会 2 学堂) Dictionary Obj = new Dictionary(); if (Kind == 1) { var query = maindb.SchoolMorningMeet.FirstOrDefault(m => m.Id == ParentId); query.StudyPerson += 1; maindb.SaveChanges(); } if (Kind == 2) { var query = maindb.SchoolMakerStudy.FirstOrDefault(m => m.Id == ParentId); query.QueryCount += 1; maindb.SaveChanges(); } return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }