SysAdminRoleController.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/[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. dataList.Add(curData);
  57. }
  58. Other.Add("Count", count); //总数
  59. return dataList;
  60. }
  61. #endregion
  62. #region 系统管理-角色管理-添加系统角色信息
  63. [Authorize]
  64. public JsonResult AddSysAdminRoleInfo(string value)
  65. {
  66. value = PublicFunction.DesDecrypt(value);
  67. JsonData data = JsonMapper.ToObject(value);
  68. AppResultJson result = AddSysAdminRoleInfoDo(value);
  69. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  70. }
  71. private AppResultJson AddSysAdminRoleInfoDo(string value)
  72. {
  73. JsonData data = JsonMapper.ToObject(value);
  74. string Name = data["Name"].ToString(); //角色名称
  75. string Details = data["Details"].ToString(); //详情
  76. string RightInfo = data["RightInfo"].ToString(); //权限字符串
  77. Dictionary<string, object> fields = new Dictionary<string, object>();
  78. fields.Add("Name", Name); //角色名称
  79. fields.Add("Details", Details); //详情
  80. fields.Add("RightInfo", RightInfo); //权限字符串
  81. var Id = int.Parse(SysAdminRoleService.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 EditSysAdminRoleInfo(string value)
  95. {
  96. value = PublicFunction.DesDecrypt(value);
  97. JsonData data = JsonMapper.ToObject(value);
  98. AppResultJson result = EditSysAdminRoleInfoDo(value);
  99. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  100. }
  101. private AppResultJson EditSysAdminRoleInfoDo(string value)
  102. {
  103. JsonData data = JsonMapper.ToObject(value);
  104. int SysAdminRoleId = int.Parse(data["SysAdminRoleId"].ToString()); //角色Id
  105. string Name = data["Name"].ToString(); //角色名称
  106. string Details = data["Details"].ToString(); //详情
  107. string RightInfo = data["RightInfo"].ToString(); //权限字符串
  108. var sysAdminRole = bsdb.SysAdminRole.FirstOrDefault(m => m.Id == SysAdminRoleId) ?? new SysAdminRole();
  109. if (sysAdminRole.Id > 0)
  110. {
  111. if (!string.IsNullOrEmpty(Name))
  112. {
  113. sysAdminRole.Name = Name;
  114. }
  115. if (!string.IsNullOrEmpty(Details))
  116. {
  117. sysAdminRole.Details = Details;
  118. }
  119. if (!string.IsNullOrEmpty(RightInfo))
  120. {
  121. sysAdminRole.RightInfo = RightInfo;
  122. }
  123. }
  124. bsdb.SaveChanges();
  125. return new AppResultJson() { Status = "1", Info = "成功" };
  126. }
  127. #endregion
  128. #region 系统管理-角色管理-删除系统角色信息
  129. [Authorize]
  130. public JsonResult DeleteSysAdminRoleInfo(string value)
  131. {
  132. value = PublicFunction.DesDecrypt(value);
  133. JsonData data = JsonMapper.ToObject(value);
  134. AppResultJson result = DeleteSysAdminRoleInfoDo(value);
  135. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  136. }
  137. private AppResultJson DeleteSysAdminRoleInfoDo(string value)
  138. {
  139. JsonData data = JsonMapper.ToObject(value);
  140. int SysAdminRoleId = int.Parse(data["SysAdminRoleId"].ToString()); //角色Id
  141. SysAdminRoleService.Delete(SysAdminRoleId);
  142. return new AppResultJson() { Status = "1", Info = "成功" };
  143. }
  144. #endregion
  145. }
  146. }