AnnouncementController.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.SystemServices;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Web.Controls.Mvc;
  10. using EMIS.ViewModel.SystemView;
  11. using Bowin.Common.Exceptions;
  12. namespace EMIS.Web.Controllers
  13. {
  14. [Authorization]
  15. public class AnnouncementController : Controller
  16. {
  17. public IAnnouncementServices AnnouncementServices { get; set; }
  18. /// <summary>
  19. /// 公告类型页面
  20. /// </summary>
  21. /// <returns></returns>
  22. public ActionResult TypeList()
  23. {
  24. return View();
  25. }
  26. [HttpPost]
  27. public ActionResult TypeList(QueryParamsModel pararms)
  28. {
  29. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  30. //避开全选值
  31. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  32. return base.Json(AnnouncementServices.GetAnnouncementTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows));
  33. }
  34. [HttpPost]
  35. public ActionResult TypeDropdownList(DropdownListBindType? bindType)
  36. {
  37. List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList()
  38. .Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
  39. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  40. DropdownList.FormatDropdownItemList(dbt, list);
  41. return base.Json(list);
  42. }
  43. /// <summary>
  44. /// 公告发布页面
  45. /// </summary>
  46. /// <returns></returns>
  47. public ActionResult List()
  48. {
  49. return View();
  50. }
  51. [HttpPost]
  52. public ActionResult List(QueryParamsModel pararms)
  53. {
  54. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  55. //避开全选值
  56. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  57. return base.Json(AnnouncementServices.GetAnnouncementViewList(configuretView, (int)pararms.page, (int)pararms.rows));
  58. }
  59. [HttpGet]
  60. public ActionResult TypeEdit(Guid? announcementTypeID)
  61. {
  62. AnnouncementTypeView announcementTypeView = new AnnouncementTypeView();
  63. if (announcementTypeID != null && announcementTypeID != Guid.Empty)
  64. {
  65. announcementTypeView = AnnouncementServices.GetAnnouncementTypeViewInfo(announcementTypeID);
  66. }
  67. return View(announcementTypeView);
  68. }
  69. [HttpGet]
  70. public ActionResult Edit(Guid? announcementID)
  71. {
  72. AnnouncementView announcementView = new AnnouncementView();
  73. if (announcementID != null && announcementID != Guid.Empty)
  74. {
  75. announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
  76. }
  77. return View(announcementView);
  78. }
  79. /// <summary>
  80. /// 保存公告类型
  81. /// </summary>
  82. /// <returns></returns>
  83. [HttpPost]
  84. public ActionResult TypeEdit(AnnouncementTypeView announcementTypeView)
  85. {
  86. try
  87. {
  88. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  89. AnnouncementServices.SaveType(announcementTypeView);
  90. return Json(new ReturnMessage()
  91. {
  92. IsSuccess = true,
  93. Message = "保存成功!"
  94. });
  95. }
  96. catch (Exception ex)
  97. {
  98. return Json(new ReturnMessage()
  99. {
  100. IsSuccess = false,
  101. Message = "保存失败:" + ex.Message
  102. });
  103. }
  104. }
  105. /// <summary>
  106. /// 保存
  107. /// </summary>
  108. /// <returns></returns>
  109. [HttpPost]
  110. public ActionResult Edit(AnnouncementView announcementView)
  111. {
  112. try
  113. {
  114. var roleList = DataGrid.GetTableData<RoleView>("dgRoleList");
  115. AnnouncementServices.Save(announcementView, roleList.Select(x => (Guid?)x.RoleID).ToList());
  116. return Json(new ReturnMessage()
  117. {
  118. IsSuccess = true,
  119. Message = "保存成功!"
  120. });
  121. }
  122. catch (Exception ex)
  123. {
  124. return Json(new ReturnMessage()
  125. {
  126. IsSuccess = false,
  127. Message = "保存失败:" + ex.Message
  128. });
  129. }
  130. }
  131. /// <summary>
  132. /// 删除公告类型
  133. /// </summary>
  134. /// <param name="roleID"></param>
  135. /// <returns></returns>
  136. [HttpPost]
  137. public ActionResult DeleteType(string typeIDs)
  138. {
  139. try
  140. {
  141. var announcementTypeIDList = typeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  142. AnnouncementServices.DeleteType(announcementTypeIDList);
  143. return base.Json("删除成功!");
  144. }
  145. catch (Exception ex)
  146. {
  147. string mge = ex.Message;
  148. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  149. if(num!=null)
  150. {
  151. if (num.Number == 547)
  152. mge = "该公告被引用请先删除所有关联的数据";
  153. }
  154. return base.Json("删除失败,原因:" + mge + "。");
  155. }
  156. }
  157. /// <summary>
  158. /// 删除
  159. /// </summary>
  160. /// <param name="roleID"></param>
  161. /// <returns></returns>
  162. [HttpPost]
  163. public ActionResult Delete(string announcementIDs)
  164. {
  165. try
  166. {
  167. var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  168. AnnouncementServices.Delete(announcementIDList);
  169. return base.Json("删除成功!");
  170. }
  171. catch (Exception ex)
  172. {
  173. return base.Json("删除失败,原因:" + ex.Message + "。");
  174. }
  175. }
  176. [HttpPost]
  177. public ActionResult GetRoleViewList(Guid? announcementID)
  178. {
  179. if (announcementID.HasValue)
  180. {
  181. var resultList = AnnouncementServices.GetAnnouncementRoleViewList(announcementID.Value);
  182. return Json(new JsonDataGridResult<RoleView> { rows = resultList, total = resultList.Count });
  183. }
  184. else
  185. {
  186. return Json(new JsonDataGridResult<RoleView>());
  187. }
  188. }
  189. /// <summary>
  190. /// 页面查询列获取公告名称
  191. /// </summary>
  192. /// <param name="bindType"></param>
  193. /// <returns></returns>
  194. [HttpPost]
  195. public ActionResult AnnouncementTypeDropdownList(DropdownListBindType? bindType)
  196. {
  197. List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList().Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
  198. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  199. DropdownList.FormatDropdownItemList(dbt, list);
  200. return base.Json(list);
  201. }
  202. [HttpPost]
  203. public ActionResult GetUserAnnouncementViewList(QueryParamsModel pararms)
  204. {
  205. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  206. return Json(AnnouncementServices.GetUserAnnouncementView(user.UserID, pararms.page.Value, pararms.rows.Value));
  207. }
  208. public ActionResult AnnouncementView(Guid announcementID)
  209. {
  210. AnnouncementView announcementView = new AnnouncementView();
  211. announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
  212. return View(announcementView);
  213. }
  214. }
  215. }