PageInfoController.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if (!string.IsNullOrEmpty(data["Title"].ToString()))
  41. {
  42. condition += " and Title like '%" + Title + "%'";
  43. }
  44. List<RelationData> relationData = new List<RelationData>();
  45. Other = new Dictionary<string, object>();
  46. int count = 0;
  47. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  48. List<Dictionary<string, object>> source = PageInfoService.List(relationData, condition, out count, pageNum, pageSize);
  49. foreach (Dictionary<string, object> subdata in source)
  50. {
  51. Dictionary<string, object> curData = new Dictionary<string, object>();
  52. curData.Add("Id", int.Parse(subdata["Id"].ToString())); //记录Id
  53. curData.Add("Title", subdata["Title"].ToString()); //标题
  54. curData.Add("Contents", subdata["Contents"].ToString()); //内容
  55. dataList.Add(curData);
  56. }
  57. Other.Add("Count", count); //总数
  58. return dataList;
  59. }
  60. #endregion
  61. #region 系统管理-协议管理-添加
  62. [Authorize]
  63. public JsonResult AddAgreementInfo(string value)
  64. {
  65. value = PublicFunction.DesDecrypt(value);
  66. JsonData data = JsonMapper.ToObject(value);
  67. AppResultJson result = AddAgreementInfoDo(value);
  68. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  69. }
  70. private AppResultJson AddAgreementInfoDo(string value)
  71. {
  72. JsonData data = JsonMapper.ToObject(value);
  73. string Title = data["Title"].ToString(); //标题
  74. string Contents = data["Contents"].ToString(); //内容
  75. Dictionary<string, object> Obj = new Dictionary<string, object>();
  76. Dictionary<string, object> fields = new Dictionary<string, object>();
  77. var sys = SysAdminService.Query(AppConfig.LoginSession.sysId);
  78. fields.Add("CreateMan", sys.AdminName + "_" + sys.RealName); //操作人
  79. fields.Add("Title", Title); //标题
  80. fields.Add("Contents", Contents); //内容
  81. var Id = int.Parse(PageInfoService.Add(fields).Data.ToString());
  82. if (Id > 0)
  83. {
  84. return new AppResultJson() { Status = "1", Info = "成功", Data = Id };
  85. }
  86. else
  87. {
  88. return new AppResultJson() { Status = "-1", Info = "失败", Data = Id };
  89. }
  90. }
  91. #endregion
  92. #region 系统管理-协议管理-编辑
  93. [Authorize]
  94. public JsonResult EditAgreementInfo(string value)
  95. {
  96. value = PublicFunction.DesDecrypt(value);
  97. JsonData data = JsonMapper.ToObject(value);
  98. AppResultJson result = EditAgreementInfoDo(value);
  99. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  100. }
  101. private AppResultJson EditAgreementInfoDo(string value)
  102. {
  103. JsonData data = JsonMapper.ToObject(value);
  104. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //记录Id
  105. string Title = data["Title"].ToString(); //标题
  106. string Contents = data["Contents"].ToString(); //内容
  107. Dictionary<string, object> Obj = new Dictionary<string, object>();
  108. var pageInfo = bsdb.PageInfo.FirstOrDefault(m => m.Id == Id) ?? new PageInfo();
  109. if (pageInfo.Id > 0)
  110. {
  111. var sys = SysAdminService.Query(AppConfig.LoginSession.sysId);
  112. pageInfo.UpdateMan = sys.AdminName + "_" + sys.RealName;
  113. if (!string.IsNullOrEmpty(Title))
  114. {
  115. pageInfo.Title = Title;
  116. }
  117. if (!string.IsNullOrEmpty(Contents))
  118. {
  119. pageInfo.Contents = Contents;
  120. }
  121. }
  122. bsdb.SaveChanges();
  123. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  124. }
  125. #endregion
  126. #region 系统管理-协议管理-删除
  127. [Authorize]
  128. public JsonResult DeleteAgreementInfo(string value)
  129. {
  130. value = PublicFunction.DesDecrypt(value);
  131. JsonData data = JsonMapper.ToObject(value);
  132. AppResultJson result = DeleteAgreementInfoDo(value);
  133. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  134. }
  135. private AppResultJson DeleteAgreementInfoDo(string value)
  136. {
  137. JsonData data = JsonMapper.ToObject(value);
  138. int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //记录Id
  139. Dictionary<string, object> Obj = new Dictionary<string, object>();
  140. PageInfoService.Delete(Id);
  141. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  142. }
  143. #endregion
  144. }
  145. }