SchoolSignInTaskRecordController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class SchoolSignInTaskRecordController : BaseController
  18. {
  19. public SchoolSignInTaskRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 商学院-任务完成提交
  23. [Authorize]
  24. public JsonResult FinishPost(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. AppResultJson result = FinishPostDo(value);
  29. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  30. }
  31. public AppResultJson FinishPostDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  35. int TaskId = int.Parse(function.CheckInt(data["TaskId"].ToString())); //任务
  36. Dictionary<string, object> Obj = new Dictionary<string, object>();
  37. SchoolSignInTaskRecord query = new SchoolSignInTaskRecord();
  38. query = maindb.SchoolSignInTaskRecord.Add(new SchoolSignInTaskRecord()
  39. {
  40. CreateDate = DateTime.Now, //创建时间
  41. UpdateDate = DateTime.Now, //修改时间
  42. UserId = UserId, //创客
  43. TaskId = TaskId, //任务
  44. }).Entity;
  45. maindb.SaveChanges();
  46. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  47. }
  48. #endregion
  49. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  50. /// <summary>
  51. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  52. /// </summary>
  53. /// <param name="value">请求的参数(json字符串)</param>
  54. /// <param name="signField">要签名的字段</param>
  55. /// <returns></returns>
  56. private string CheckSign(string value, string[] signField)
  57. {
  58. JsonData json = JsonMapper.ToObject(value);
  59. Dictionary<string, string> dic = new Dictionary<string, string>();
  60. for (int i = 0; i < signField.Length; i++)
  61. {
  62. dic.Add(signField[i], json[signField[i]].ToString());
  63. }
  64. string sign = json["sign"].ToString(); //客户端签名字符串
  65. return new Sign().sign(dic, sign);
  66. }
  67. #endregion
  68. }
  69. }