public JsonResult GetModel(string id) { string forwardID = Request["ForwardID"]; string replyID = Request["ReplyID"]; UserInfo user = FormulaHelper.GetUserInfo(); string orgUser = string.IsNullOrEmpty(user.UserOrgName) ? user.UserName : user.UserOrgName + " " + user.UserName; if (!string.IsNullOrEmpty(forwardID)) { var msg = entities.Set <S_S_MsgBody>().Where(c => c.ID == forwardID).SingleOrDefault(); msg.ID = ""; msg.ParentID = forwardID; msg.ReceiverIDs = ""; msg.ReceiverNames = ""; msg.Title = "转发:" + msg.Title; msg.Content = "<p> </p><p></p><p></p><p></p><p>" + orgUser + "</p><hr />" + msg.Content; msg.IsReadReceipt = "0"; return(Json(msg)); } else if (!string.IsNullOrEmpty(replyID)) { var msg = entities.Set <S_S_MsgBody>().Where(c => c.ID == replyID).SingleOrDefault(); msg.ID = ""; msg.ParentID = replyID; msg.ReceiverIDs = msg.SenderID; msg.ReceiverNames = msg.SenderName; msg.Title = "回复:" + msg.Title; msg.Content = "<p> </p><p></p><p><p></p><p></p>" + orgUser + "</p><hr />" + msg.Content; msg.IsReadReceipt = "0"; return(Json(msg)); } else { // var msg = entities.Set<S_S_MsgBody>().Where(c => c.ID == id).SingleOrDefault(); string userID = user.UserID; S_S_MsgReceiver receiver = entities.Set <S_S_MsgReceiver>().FirstOrDefault(c => c.MsgBodyID == id && c.UserID == userID && c.FirstViewTime == null); if (receiver != null) { receiver.FirstViewTime = DateTime.Now; S_S_MsgBody msg = entities.Set <S_S_MsgBody>().FirstOrDefault(c => c.ID == id); if (msg != null) { //需要已读回执 if (msg.IsReadReceipt == "1") { string content = "<p style=\"text-align:left;text-indent:-72pt;margin-left:72pt;\" align=\"left\"><span style=\"font-family:宋体;\">消息</span></p>" + "<p style=\"text-align:left;text-indent:-72pt;margin-left:72pt;\" align=\"left\"><span style=\"font-family:宋体;\"></span></p>" + "<p style=\"text-align:left;text-indent:-72pt;margin-left:72pt;\" align=\"left\"><span style=\"font-family:宋体;\"><span> </span>接收人:<span> </span>{0}</span></p>" + "<p style=\"text-align:left;text-indent:-72pt;margin-left:72pt;\" align=\"left\"><span style=\"font-family:宋体;\"><span> </span>标题:<span> </span>{1}</span></p>" + "<p style=\"text-align:left;text-indent:-72pt;margin-left:72pt;\" align=\"left\"><span style=\"font-family:宋体;\"><span> </span>发送时间:<span> </span>{2}</span></p>" + "<p style=\"text-align:left;\" align=\"left\"><span style=\"font-family:宋体;\"></span></p>" + "<p style=\"text-align:left;\" align=\"left\"><span style=\"font-family:宋体;\">阅读时间为 {3}</span></p>"; content = string.Format(content, receiver.UserName, msg.Title, msg.SendTime, receiver.FirstViewTime); new MessageService().SendMsg("已读:" + msg.Title, content, string.Empty, string.Empty, msg.SenderID, msg.SenderName, null); } } entities.SaveChanges(); } return(base.JsonGetModel <S_S_MsgBody>(id)); } }
public void Save(string data) { var entitie = FormulaHelper.GetEntities <BaseEntities>(); var list = JsonHelper.ToObject <List <Dictionary <string, string> > >(data); string flowID = getQueryValue(list, "flowID"); string nodeID = getQueryValue(list, "nodeID"); string ids = getQueryValue(list, "ids"); string content = getQueryValue(list, "comment"); DataTable dt = GetFlowExec(flowID); if (dt == null) { return; } foreach (DataRow dr in dt.Rows) { if (dr["ID"].ToString() == nodeID) { string receiverIDs = dr["TaskUserID"].ToString(); string receiverNames = FormulaHelper.GetUserInfoByID(receiverIDs).UserName; if (ids.Length > 0) { receiverIDs += "," + ids; foreach (string userId in ids.Split(',')) { receiverNames += "," + FormulaHelper.GetUserInfoByID(userId).UserName; } } S_S_MsgBody body = new S_S_MsgBody(); string msgBodyId = FormulaHelper.CreateGuid(); body.ID = msgBodyId; body.Title = "关于《" + dr["FlowName"].ToString() + "》的回复"; body.Content = content; body.ContentText = content; #region 去除url中的token var lowerUrl = Request.UrlReferrer.ToString().ToLower(); var lowerParam = !String.IsNullOrEmpty(ConfigurationManager.AppSettings["TokenKey"]) ? ConfigurationManager.AppSettings["TokenKey"] : "GWToken"; lowerParam = lowerParam.ToLower(); if (lowerUrl.IndexOf("&" + lowerParam) > 0) { var beginUrl = Request.UrlReferrer.ToString().Substring(0, lowerUrl.IndexOf("&" + lowerParam)); var endUrl = Request.UrlReferrer.ToString().Substring(lowerUrl.IndexOf("&" + lowerParam) + 1, Request.UrlReferrer.ToString().Length - lowerUrl.IndexOf("&" + lowerParam) - 1); if (endUrl.IndexOf("&") > 0) { endUrl = endUrl.Substring(endUrl.IndexOf("&"), endUrl.Length - endUrl.IndexOf("&")); } else { endUrl = ""; } body.LinkUrl = beginUrl + endUrl; } else if (lowerUrl.IndexOf("?" + lowerParam) > 0) { var beginUrl = Request.UrlReferrer.ToString().Substring(0, lowerUrl.IndexOf("?" + lowerParam)); var endUrl = Request.UrlReferrer.ToString().Substring(lowerUrl.IndexOf("?" + lowerParam) + 1, Request.UrlReferrer.ToString().Length - lowerUrl.IndexOf("?" + lowerParam) - 1); if (endUrl.IndexOf("&") > 0) { endUrl = "?" + endUrl.Substring(endUrl.IndexOf("&") + 1, endUrl.Length - endUrl.IndexOf("&") - 1); } else { endUrl = ""; } body.LinkUrl = beginUrl + endUrl; } else { body.LinkUrl = Request.UrlReferrer.ToString(); } #endregion body.IsSystemMsg = "0"; body.SendTime = DateTime.Now; body.SenderID = FormulaHelper.UserID; body.SenderName = FormulaHelper.GetUserInfo().UserName; body.ReceiverIDs = receiverIDs; body.ReceiverNames = receiverNames; body.AttachFileIDs = getQueryValue(list, "fileID"); body.FlowMsgID = nodeID; entitie.Set <S_S_MsgBody>().Add(body); entitie.SaveChanges(); foreach (string receiverID in receiverIDs.Split(',')) { SaveReceiver(msgBodyId, receiverID); } } } }