PageInfoController.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.Models.Bs;
  11. using MySystem.Service.Bs;
  12. using LitJson;
  13. using Library;
  14. namespace MySystem.Areas.Api.Controllers.v1.Bs
  15. {
  16. [Area("Api")]
  17. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  18. public class PageInfoController : BaseController
  19. {
  20. public PageInfoController(IHttpContextAccessor accessor) : base(accessor)
  21. {
  22. }
  23. #region 系统管理-协议管理-列表
  24. [Authorize]
  25. public JsonResult AgreementInfoList(string value)
  26. {
  27. value = PublicFunction.DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. Dictionary<string, object> Other = new Dictionary<string, object>();
  30. List<Dictionary<string, object>> dataList = AgreementInfoListDo(value, out Other);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  32. }
  33. private List<Dictionary<string, object>> AgreementInfoListDo(string value, out Dictionary<string, object> Other)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. string Title = data["Title"].ToString(); //标题
  37. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  38. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  39. string condition = "";
  40. List<RelationData> relationData = new List<RelationData>();
  41. Other = new Dictionary<string, object>();
  42. int count = 0;
  43. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  44. List<Dictionary<string, object>> source = PageInfoService.List(relationData, condition, out count, pageNum, pageSize);
  45. foreach (Dictionary<string, object> subdata in source)
  46. {
  47. Dictionary<string, object> curData = new Dictionary<string, object>();
  48. curData.Add("Id", int.Parse(subdata["Id"].ToString())); //记录Id
  49. curData.Add("Title", subdata["Title"].ToString()); //标题
  50. curData.Add("Contents", subdata["Contents"].ToString()); //内容
  51. dataList.Add(curData);
  52. }
  53. Other.Add("Count", count); //总数
  54. return dataList;
  55. }
  56. #endregion
  57. #region 系统管理-协议管理-添加
  58. [Authorize]
  59. public JsonResult AddAgreementInfo(string value)
  60. {
  61. value = PublicFunction.DesDecrypt(value);
  62. JsonData data = JsonMapper.ToObject(value);
  63. AppResultJson result = AddAgreementInfoDo(value);
  64. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  65. }
  66. private AppResultJson AddAgreementInfoDo(string value)
  67. {
  68. JsonData data = JsonMapper.ToObject(value);
  69. string Title = data["Title"].ToString(); //标题
  70. string Contents = data["Contents"].ToString(); //内容
  71. Dictionary<string, object> Obj = new Dictionary<string, object>();
  72. Dictionary<string, object> fields = new Dictionary<string, object>();
  73. var sys = SysAdminService.Query(AppConfig.LoginSession.sysId);
  74. fields.Add("CreateMan", sys.AdminName + "_" + sys.RealName); //操作人
  75. fields.Add("Title", Title); //标题
  76. fields.Add("Contents", Contents); //内容
  77. var Id = int.Parse(PageInfoService.Add(fields).Data.ToString());
  78. if (Id > 0)
  79. {
  80. return new AppResultJson() { Status = "1", Info = "成功", Data = Id };
  81. }
  82. else
  83. {
  84. return new AppResultJson() { Status = "-1", Info = "失败", Data = Id };
  85. }
  86. }
  87. #endregion
  88. #region 系统管理-协议管理-编辑
  89. [Authorize]
  90. public JsonResult EditAgreementInfo(string value)
  91. {
  92. value = PublicFunction.DesDecrypt(value);
  93. JsonData data = JsonMapper.ToObject(value);
  94. AppResultJson result = EditAgreementInfoDo(value);
  95. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  96. }
  97. private AppResultJson EditAgreementInfoDo(string value)
  98. {
  99. JsonData data = JsonMapper.ToObject(value);
  100. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //记录Id
  101. string Title = data["Title"].ToString(); //标题
  102. string Contents = data["Contents"].ToString(); //内容
  103. Dictionary<string, object> Obj = new Dictionary<string, object>();
  104. var pageInfo = bsdb.PageInfo.FirstOrDefault(m => m.Id == Id) ?? new PageInfo();
  105. if (pageInfo.Id > 0)
  106. {
  107. var sys = SysAdminService.Query(AppConfig.LoginSession.sysId);
  108. pageInfo.UpdateMan = sys.AdminName + "_" + sys.RealName;
  109. if (!string.IsNullOrEmpty(Title))
  110. {
  111. pageInfo.Title = Title;
  112. }
  113. if (!string.IsNullOrEmpty(Contents))
  114. {
  115. pageInfo.Contents = Contents;
  116. }
  117. }
  118. bsdb.SaveChanges();
  119. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  120. }
  121. #endregion
  122. #region 系统管理-协议管理-删除
  123. [Authorize]
  124. public JsonResult DeleteAgreementInfo(string value)
  125. {
  126. value = PublicFunction.DesDecrypt(value);
  127. JsonData data = JsonMapper.ToObject(value);
  128. AppResultJson result = DeleteAgreementInfoDo(value);
  129. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  130. }
  131. private AppResultJson DeleteAgreementInfoDo(string value)
  132. {
  133. JsonData data = JsonMapper.ToObject(value);
  134. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //记录Id
  135. Dictionary<string, object> Obj = new Dictionary<string, object>();
  136. PageInfoService.Delete(Id);
  137. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  138. }
  139. #endregion
  140. }
  141. }