足力健后端,使用.netcore版本,合并1个项目使用

ModuleButtonInfoController.cs 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IRepositories;
  4. using System.Linq;
  5. using System.Model;
  6. using System.Security.Claims;
  7. using System.Threading.Tasks;
  8. using System.Web;
  9. using System.Common;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using TVShoppingCallCenter_ZLJ.Models.Dtos;
  13. namespace TVShoppingCallCenter_ZLJ.Controllers.System
  14. {
  15. [Authorize]
  16. [Produces("application/json")]
  17. [Route("api/[controller]")]
  18. public class ModuleButtonInfoController : BaseController
  19. {
  20. private readonly ISys_ModuleButtonInfoRepository _sys_modulebuttoninfoRepository;
  21. public ModuleButtonInfoController(ISys_ModuleButtonInfoRepository sys_modulebuttoninfoRepository)
  22. {
  23. _sys_modulebuttoninfoRepository = sys_modulebuttoninfoRepository;
  24. }
  25. [HttpGet("getlist")]
  26. public async Task<IActionResult> GetListAsync(int menuid = 0)
  27. {
  28. var list_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetListALL(b => b.F_State == (int)EnumDelState.Enabled && b.F_MenuId == menuid, o => o.F_Sort, SqlSugar.OrderByType.Asc);
  29. List<ModuleInfoButtonDto> list_ModuleInfoButtonDto = new List<ModuleInfoButtonDto>();
  30. foreach (var entity in list_ModuleInfoButton)
  31. {
  32. ModuleInfoButtonDto _dto = new ModuleInfoButtonDto
  33. {
  34. id = entity.F_Id,
  35. moduleid = entity.F_MenuId.Value,
  36. name = entity.F_ButtonName,
  37. jsevent = entity.F_JSEvent,
  38. icon = entity.F_Icon,
  39. url = entity.F_UrlAddress,
  40. flag = entity.F_State.Value,
  41. remark = entity.F_Remark,
  42. sort = entity.F_Sort.Value
  43. };
  44. list_ModuleInfoButtonDto.Add(_dto);
  45. }
  46. return Success("获取按钮", list_ModuleInfoButton);
  47. }
  48. /// <summary>
  49. /// 获取菜单按钮实体
  50. /// </summary>
  51. /// <param name="mId"></param>
  52. /// <returns></returns>
  53. [HttpGet("getmodule")]
  54. public async Task<IActionResult> GetModuleAsync(int mid = 0)
  55. {
  56. var entity = (await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == mid));
  57. if (entity != null)
  58. {
  59. ModuleInfoButtonDto _dto = new ModuleInfoButtonDto
  60. {
  61. id = entity.F_Id,
  62. moduleid = entity.F_MenuId.Value,
  63. name = entity.F_ButtonName,
  64. jsevent = entity.F_JSEvent,
  65. code = entity.F_ButtonCode,
  66. icon = entity.F_Icon,
  67. url = entity.F_UrlAddress,
  68. flag = entity.F_State.Value,
  69. remark = entity.F_Remark,
  70. sort = entity.F_Sort.Value
  71. };
  72. return Success("加载按钮成功", _dto);
  73. }
  74. else
  75. {
  76. return Error("加载按钮失败");
  77. }
  78. }
  79. /// <summary>
  80. /// 添加按钮
  81. /// </summary>
  82. /// <param name="input"></param>
  83. /// <returns></returns>
  84. [HttpPost("addmodule")]
  85. public async Task<IActionResult> AddModule(ModuleInfoButtonDto input)
  86. {
  87. if (input.moduleid>0)
  88. return Error("参数错误");
  89. if (string.IsNullOrEmpty(input.name))
  90. return Error("请输入按钮名称");
  91. if (string.IsNullOrEmpty(input.code))
  92. return Error("请输入按钮代码");
  93. var entity_ModuleInfoButton = new T_Sys_ModuleButtonInfo();
  94. entity_ModuleInfoButton.F_MenuId = input.moduleid;
  95. entity_ModuleInfoButton.F_ButtonCode = input.code;
  96. entity_ModuleInfoButton.F_ButtonName = input.name;
  97. entity_ModuleInfoButton.F_JSEvent = input.jsevent;
  98. entity_ModuleInfoButton.F_Icon = input.icon;
  99. entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url);
  100. entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag);
  101. entity_ModuleInfoButton.F_Remark = input.remark;
  102. entity_ModuleInfoButton.F_Sort = input.sort;
  103. entity_ModuleInfoButton.F_CreateOn = DateTime.Now.ToLocalTime();
  104. entity_ModuleInfoButton.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  105. var res = await _sys_modulebuttoninfoRepository.Add(entity_ModuleInfoButton);
  106. if (res>0)
  107. {
  108. return Success("按钮添加成功");
  109. }
  110. else
  111. {
  112. return Error("菜单按钮添加失败,请重试!");
  113. }
  114. }
  115. /// <summary>
  116. /// 更新按钮
  117. /// </summary>
  118. /// <param name="input"></param>
  119. /// <returns></returns>
  120. [HttpPost("updatemodule")]
  121. public async Task<IActionResult> UpdateModule(ModuleInfoButtonDto input)
  122. {
  123. if (input.moduleid > 0)
  124. return Error("参数错误");
  125. if (string.IsNullOrEmpty(input.name))
  126. return Error("请输入按钮名称");
  127. if (string.IsNullOrEmpty(input.code))
  128. return Error("请输入按钮代码");
  129. var entity_ModuleInfoButton = new T_Sys_ModuleButtonInfo();
  130. entity_ModuleInfoButton.F_Id = input.id;
  131. entity_ModuleInfoButton.F_MenuId = input.moduleid;
  132. entity_ModuleInfoButton.F_ButtonCode = input.code;
  133. entity_ModuleInfoButton.F_ButtonName = input.name;
  134. entity_ModuleInfoButton.F_JSEvent = input.jsevent;
  135. entity_ModuleInfoButton.F_Icon = input.icon;
  136. entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url);
  137. entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag);
  138. entity_ModuleInfoButton.F_Remark = input.remark;
  139. entity_ModuleInfoButton.F_Sort = input.sort;
  140. entity_ModuleInfoButton.F_LastModifyOn = DateTime.Now.ToLocalTime();
  141. entity_ModuleInfoButton.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  142. if (await _sys_modulebuttoninfoRepository.Update(entity_ModuleInfoButton))
  143. {
  144. return Success("按钮修改成功");
  145. }
  146. else
  147. {
  148. return Error("按钮修改失败,请重试!");
  149. }
  150. }
  151. /// <summary>
  152. /// 删除菜单按钮
  153. /// </summary>
  154. /// <param name="ids"></param>
  155. /// <returns></returns>
  156. [HttpPost("delmodule")]
  157. public async Task<IActionResult> DelModuleAsync(int[] ids)
  158. {
  159. var res = 0;
  160. if (ids != null && ids.Length > 0)
  161. {
  162. foreach (var item in ids)
  163. {
  164. var ml = await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == item);
  165. ml.F_State = (int)EnumDelState.Delete;
  166. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  167. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  168. if (_sys_modulebuttoninfoRepository.Update(ml).Result)
  169. res += 1;
  170. }
  171. if (res == ids.Length)
  172. return Success("删除成功");
  173. else if (res > 0 && res < ids.Length)
  174. return Error("部分删除失败,请查看后重新操作");
  175. else
  176. return Error("删除失败,请查看后重新操作");
  177. }
  178. else
  179. {
  180. return Error("请选择要删除的记录");
  181. }
  182. }
  183. /// <summary>
  184. /// 编辑菜单按钮
  185. /// </summary>
  186. /// <param name="input"></param>
  187. /// <returns></returns>
  188. [HttpPost("editmodule")]
  189. public async Task<IActionResult> EditModuleAsync(ModuleInfoButtonDto input)
  190. {
  191. if (input.moduleid > 0)
  192. return Error("参数错误");
  193. if (string.IsNullOrEmpty(input.name))
  194. return Error("请输入按钮名称");
  195. if (string.IsNullOrEmpty(input.code))
  196. return Error("请输入按钮代码");
  197. var entity_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetSingle(x=>x.F_Id==input.id);
  198. if (entity_ModuleInfoButton != null)
  199. {
  200. entity_ModuleInfoButton.F_MenuId = input.moduleid;
  201. entity_ModuleInfoButton.F_ButtonCode = input.code;
  202. entity_ModuleInfoButton.F_ButtonName = input.name;
  203. entity_ModuleInfoButton.F_JSEvent = input.jsevent;
  204. entity_ModuleInfoButton.F_Icon = input.icon;
  205. entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url);
  206. entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag);
  207. entity_ModuleInfoButton.F_Remark = input.remark;
  208. entity_ModuleInfoButton.F_Sort = input.sort;
  209. entity_ModuleInfoButton.F_LastModifyOn = DateTime.Now.ToLocalTime();
  210. entity_ModuleInfoButton.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  211. if (await _sys_modulebuttoninfoRepository.Update(entity_ModuleInfoButton))
  212. {
  213. return Success("按钮修改成功");
  214. }
  215. else
  216. {
  217. return Error("按钮修改失败,请重试!");
  218. }
  219. }
  220. else
  221. {
  222. return Error("菜单对象获取失败");
  223. }
  224. }
  225. }
  226. }