123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.ViewModel;
- using EMIS.Web.Controls;
- using Bowin.Web.Controls.Mvc;
- using EMIS.ViewModel.SystemView;
- using Bowin.Common.Exceptions;
- namespace EMIS.Web.Controllers
- {
- [Authorization]
- public class AnnouncementController : Controller
- {
- public IAnnouncementServices AnnouncementServices { get; set; }
- /// <summary>
- /// 公告类型页面
- /// </summary>
- /// <returns></returns>
- public ActionResult TypeList()
- {
- return View();
- }
- [HttpPost]
- public ActionResult TypeList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(AnnouncementServices.GetAnnouncementTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows));
- }
- [HttpPost]
- public ActionResult TypeDropdownList(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList()
- .Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- /// 公告发布页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- return View();
- }
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(AnnouncementServices.GetAnnouncementViewList(configuretView, (int)pararms.page, (int)pararms.rows));
- }
- [HttpGet]
- public ActionResult TypeEdit(Guid? announcementTypeID)
- {
- AnnouncementTypeView announcementTypeView = new AnnouncementTypeView();
- if (announcementTypeID != null && announcementTypeID != Guid.Empty)
- {
- announcementTypeView = AnnouncementServices.GetAnnouncementTypeViewInfo(announcementTypeID);
- }
- return View(announcementTypeView);
- }
- [HttpGet]
- public ActionResult Edit(Guid? announcementID)
- {
- AnnouncementView announcementView = new AnnouncementView();
- if (announcementID != null && announcementID != Guid.Empty)
- {
- announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
- }
- return View(announcementView);
- }
- /// <summary>
- /// 保存公告类型
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult TypeEdit(AnnouncementTypeView announcementTypeView)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- AnnouncementServices.SaveType(announcementTypeView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(AnnouncementView announcementView)
- {
- try
- {
- var roleList = DataGrid.GetTableData<RoleView>("dgRoleList");
- AnnouncementServices.Save(announcementView, roleList.Select(x => (Guid?)x.RoleID).ToList());
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除公告类型
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult DeleteType(string typeIDs)
- {
- try
- {
- var announcementTypeIDList = typeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
- AnnouncementServices.DeleteType(announcementTypeIDList);
- return base.Json("删除成功!");
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
- if(num!=null)
- {
- if (num.Number == 547)
- mge = "该公告被引用请先删除所有关联的数据";
- }
- return base.Json("删除失败,原因:" + mge + "。");
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string announcementIDs)
- {
- try
- {
- var announcementIDList = announcementIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
- AnnouncementServices.Delete(announcementIDList);
- return base.Json("删除成功!");
- }
- catch (Exception ex)
- {
- return base.Json("删除失败,原因:" + ex.Message + "。");
- }
- }
- [HttpPost]
- public ActionResult GetRoleViewList(Guid? announcementID)
- {
- if (announcementID.HasValue)
- {
- var resultList = AnnouncementServices.GetAnnouncementRoleViewList(announcementID.Value);
- return Json(new JsonDataGridResult<RoleView> { rows = resultList, total = resultList.Count });
- }
- else
- {
- return Json(new JsonDataGridResult<RoleView>());
- }
- }
- /// <summary>
- /// 页面查询列获取公告名称
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult AnnouncementTypeDropdownList(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = AnnouncementServices.GetUsableAnnouncementTypeViewList().Select(x => new DropdownListItem { Text = x.Name, Value = x.AnnouncementTypeID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- [HttpPost]
- public ActionResult GetUserAnnouncementViewList(QueryParamsModel pararms)
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- return Json(AnnouncementServices.GetUserAnnouncementView(user.UserID, pararms.page.Value, pararms.rows.Value));
- }
- public ActionResult AnnouncementView(Guid announcementID)
- {
- AnnouncementView announcementView = new AnnouncementView();
- announcementView = AnnouncementServices.GetAnnouncementViewInfo(announcementID);
- return View(announcementView);
- }
- }
- }
|