SysAdminRoleController.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * 后台角色
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.AspNetCore.Http;
  9. using MySystem.Models.Bs;
  10. using Library;
  11. using LitJson;
  12. using Microsoft.AspNetCore.Authorization;
  13. using MySystem.Service.Bs;
  14. using System.Linq;
  15. namespace MySystem.Areas.Api.Controllers.v1
  16. {
  17. [Area("Api")]
  18. [Route("Api/v1/QrCodePlateMain/[controller]/[action]")]
  19. public class SysAdminRoleController : BaseController
  20. {
  21. public SysAdminRoleController(IHttpContextAccessor accessor) : base(accessor)
  22. {
  23. }
  24. #region 系统管理-角色管理-角色列表
  25. [Authorize]
  26. public JsonResult SysAdminRoleList(string value)
  27. {
  28. value = PublicFunction.DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> Other = new Dictionary<string, object>();
  31. List<Dictionary<string, object>> dataList = SysAdminRoleListDo(value, out Other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  33. }
  34. private List<Dictionary<string, object>> SysAdminRoleListDo(string value, out Dictionary<string, object> Other)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. string Name = data["Name"].ToString(); //角色名称
  38. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  39. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  40. List<RelationData> relationData = new List<RelationData>();
  41. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  42. string condition = "";
  43. if (!string.IsNullOrEmpty(data["Name"].ToString()))
  44. {
  45. condition += " and Name like '%" + Name + "%'";
  46. }
  47. Other = new Dictionary<string, object>();
  48. int count = 0;
  49. List<Dictionary<string, object>> source = SysAdminRoleService.List(relationData, condition, out count, pageNum, pageSize);
  50. foreach (Dictionary<string, object> subdata in source)
  51. {
  52. Dictionary<string, object> curData = new Dictionary<string, object>();
  53. curData.Add("Id", int.Parse(subdata["Id"].ToString())); //Id
  54. curData.Add("Name", subdata["Name"].ToString()); //角色名称
  55. curData.Add("Details", subdata["Details"].ToString()); //描述
  56. curData.Add("RightInfo", subdata["RightInfo"].ToString()); //权限字符串
  57. dataList.Add(curData);
  58. }
  59. Other.Add("Count", count); //总数
  60. return dataList;
  61. }
  62. #endregion
  63. #region 系统管理-角色管理-添加系统角色信息
  64. [Authorize]
  65. public JsonResult AddSysAdminRoleInfo(string value)
  66. {
  67. value = PublicFunction.DesDecrypt(value);
  68. JsonData data = JsonMapper.ToObject(value);
  69. AppResultJson result = AddSysAdminRoleInfoDo(value);
  70. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  71. }
  72. private AppResultJson AddSysAdminRoleInfoDo(string value)
  73. {
  74. JsonData data = JsonMapper.ToObject(value);
  75. string Name = data["Name"].ToString(); //角色名称
  76. string Details = data["Details"].ToString(); //详情
  77. string RightInfo = data["RightInfo"].ToString(); //权限字符串
  78. Dictionary<string, object> fields = new Dictionary<string, object>();
  79. fields.Add("Name", Name); //角色名称
  80. fields.Add("Details", Details); //详情
  81. fields.Add("RightInfo", RightInfo); //权限字符串
  82. var Id = int.Parse(SysAdminRoleService.Add(fields).Data.ToString());
  83. if (Id > 0)
  84. {
  85. return new AppResultJson() { Status = "1", Info = "成功", Data = Id };
  86. }
  87. else
  88. {
  89. return new AppResultJson() { Status = "-1", Info = "失败", Data = Id };
  90. }
  91. }
  92. #endregion
  93. #region 系统管理-角色管理-编辑系统角色信息
  94. [Authorize]
  95. public JsonResult EditSysAdminRoleInfo(string value)
  96. {
  97. value = PublicFunction.DesDecrypt(value);
  98. JsonData data = JsonMapper.ToObject(value);
  99. AppResultJson result = EditSysAdminRoleInfoDo(value);
  100. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  101. }
  102. private AppResultJson EditSysAdminRoleInfoDo(string value)
  103. {
  104. JsonData data = JsonMapper.ToObject(value);
  105. int SysAdminRoleId = int.Parse(data["SysAdminRoleId"].ToString()); //角色Id
  106. string Name = data["Name"].ToString(); //角色名称
  107. string Details = data["Details"].ToString(); //详情
  108. string RightInfo = data["RightInfo"].ToString(); //权限字符串
  109. var sysAdminRole = bsdb.SysAdminRole.FirstOrDefault(m => m.Id == SysAdminRoleId) ?? new SysAdminRole();
  110. if (sysAdminRole.Id > 0)
  111. {
  112. if (!string.IsNullOrEmpty(Name))
  113. {
  114. sysAdminRole.Name = Name;
  115. }
  116. if (!string.IsNullOrEmpty(Details))
  117. {
  118. sysAdminRole.Details = Details;
  119. }
  120. if (!string.IsNullOrEmpty(RightInfo))
  121. {
  122. sysAdminRole.RightInfo = RightInfo;
  123. }
  124. }
  125. bsdb.SaveChanges();
  126. return new AppResultJson() { Status = "1", Info = "成功" };
  127. }
  128. #endregion
  129. #region 系统管理-角色管理-删除系统角色信息
  130. [Authorize]
  131. public JsonResult DeleteSysAdminRoleInfo(string value)
  132. {
  133. value = PublicFunction.DesDecrypt(value);
  134. JsonData data = JsonMapper.ToObject(value);
  135. AppResultJson result = DeleteSysAdminRoleInfoDo(value);
  136. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  137. }
  138. private AppResultJson DeleteSysAdminRoleInfoDo(string value)
  139. {
  140. JsonData data = JsonMapper.ToObject(value);
  141. int SysAdminRoleId = int.Parse(data["SysAdminRoleId"].ToString()); //角色Id
  142. SysAdminRoleService.Delete(SysAdminRoleId);
  143. return new AppResultJson() { Status = "1", Info = "成功" };
  144. }
  145. #endregion
  146. }
  147. }