using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL; using CRM.Core.BLL.Base; using CRM.Core.BLL.Csvr; using CRM.Core.Common.Layui; using CRM.Core.Common.WebHelper; using CRM.Core.Model.Entity; using System; using System.Data.SqlClient; using System.Linq; using System.Web.Mvc; using WX.CRM.Common; namespace Core.Web.Controllers { public class MessageController : BaseController { private BAS_ROLE_BL _role = new BAS_ROLE_BL(); private BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL(); private Csvr_Message_Type_BL _msgtype = new Csvr_Message_Type_BL(); private Csvr_Message_BL _msg = new Csvr_Message_BL(); ValidationErrors errors = new ValidationErrors(); [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_消息类型配置, ToolBarConfig.CONST_NotButton, true)] public ActionResult Index() { ViewBag.rightCode = RightsConfig.CONST_消息类型配置; return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_消息类型配置, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetTypeList(Laypage pager, MesgTypeQueryDto dto) { var where = PredicateExtensionses.True(); if (!string.IsNullOrEmpty(dto.msgcode)) { where = where.And(p => p.msgcode == dto.msgcode); } if (!string.IsNullOrEmpty(dto.title)) { where = where.And(p => p.title.Contains(dto.title)); } if (!string.IsNullOrEmpty(dto.sendtype)) { where = where.And(p => p.sendtype == dto.sendtype); } if (dto.status.HasValue) { where = where.And(p => p.status == dto.status.Value); } var list = _msgtype.GetList(where, p => p.sort, pager, SortOrder.Ascending).ToList(); var data = new LayuiData() { msg = "数据加载成功!", count = pager.count, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_消息类型配置, ToolBarConfig.CONST_Add, true)] public ActionResult Edit(int? id) { Csvr_Message_Type messagetype = new Csvr_Message_Type() { status = 1, sendtype = "eid" }; if (id.HasValue) { messagetype = _msgtype.Get(m => m.id == id.Value); } ViewBag.ModelJson = JsonHelper.NewtonsoftToJson(messagetype); return View(messagetype); } [AuthorizeRedirect(RightsConfig.CONST_消息类型配置, ToolBarConfig.CONST_Add, false)] public JsonResult MsgTypeSave(Csvr_Message_Type model) { if (model.sendtype == "all") { model.sendConfig = ""; } else if (model.sendtype == "role") { string[] models = model.sendConfig.Split(','); foreach (var item in models) { if (!string.IsNullOrEmpty(item) && _role.Get(m => m.CODE == item) == null) { return Json(new { result = false, code = -1, msg = "接收对象“" + item + "”错误!" }, JsonRequestBehavior.AllowGet); } } } else if (model.sendtype == "eid") { string[] models = model.sendConfig.Split(','); foreach (var item in models) { if (string.IsNullOrEmpty(item)) continue; int meid = 0; if (!int.TryParse(item, out meid)) return Json(new { result = false, code = -1, msg = "接收对象“" + item + "”错误!" }, JsonRequestBehavior.AllowGet); if (_user.Get(m => m.EID == meid) == null) { return Json(new { result = false, code = -1, msg = "接收对象“" + item + "”错误!" }, JsonRequestBehavior.AllowGet); } } } if (model.id == 0) { var entry = _msgtype.Get(p => p.msgcode == model.msgcode); if (entry != null) { return Json(new { result = false, code = -1, msg = "编码已被占用,请更换!" }, JsonRequestBehavior.AllowGet); } model.ctime = DateTime.Now; model.createuser = Eid; _msgtype.Add(model); } else { model.utime = DateTime.Now; model.updateuser = Eid; var entry = _msgtype.Get(p => p.id == model.id); if (model != null) { var entry2 = _msgtype.Get(p => p.msgcode == model.msgcode && p.id != entry.id); if (entry2 != null) { return Json(new { result = false, code = -1, msg = "编码已被占用,请更换!" }, JsonRequestBehavior.AllowGet); } entry.msgcode = model.msgcode; entry.title = model.title; entry.updateuser = model.updateuser; entry.utime = model.utime; entry.content = model.content; entry.sendtype = model.sendtype; entry.sendConfig = model.sendConfig; entry.status = model.status; entry.sort = model.sort; _msgtype.Update(entry); } else { return Json(new { result = false, code = -1, msg = "参数错误!" }, JsonRequestBehavior.AllowGet); } } return Json(new { result = true, code = 0, msg = "保存成功!" }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_消息类型配置, ToolBarConfig.CONST_Delete, false)] public JsonResult Delete(int id) { try { var entry2 = _msgtype.Get(p => p.id == id); if (entry2 == null) { return Json(new { result = false, code = -1, msg = "参数错误!" }, JsonRequestBehavior.AllowGet); } _msgtype.Delete(entry2); return Json(new { result = true, code = 0, msg = "删除成功!" }, JsonRequestBehavior.AllowGet); } catch (Exception e) { LogHelper.Error(e.ToString()); return Json(new { result = false, code = -1, msg = "参数错误!" }, JsonRequestBehavior.AllowGet); } } } public class MesgTypeQueryDto { public string msgcode { get; set; } public string title { get; set; } public string sendtype { get; set; } public int? status { get; set; } } }