public override JsonResult Save() { var msg = UpdateEntity <S_S_MsgBody>(); var user = FormulaHelper.GetUserInfo(); msg.SenderID = user.UserID; msg.SenderName = user.UserName; msg.SendTime = DateTime.Now; if (msg.Content.Length > 2000) { throw new BusinessException("消息长度不能超过2000个字符!"); } List <S_S_MsgReceiver> listReceiver = new List <S_S_MsgReceiver>(); if (!string.IsNullOrEmpty(msg.ReceiverIDs) && !string.IsNullOrEmpty(msg.ReceiverNames)) { string[] receiverIDs = msg.ReceiverIDs.Split(','); string[] receiverNames = msg.ReceiverNames.Split(','); for (int i = 0; i < receiverIDs.Length; i++) { S_S_MsgReceiver receiver = new S_S_MsgReceiver(); receiver.ID = FormulaHelper.CreateGuid(); receiver.MsgBodyID = msg.ID; receiver.UserID = receiverIDs[i]; receiver.UserName = receiverNames[i]; listReceiver.Add(receiver); } } if (!string.IsNullOrEmpty(msg.ReceiverDeptIDs)) { string[] arrDeptID = msg.ReceiverDeptIDs.Split(','); List <S_A_User> list = base.DataBaseFilter <S_A_User>(entities.Set <S_A__OrgUser>().Where(c => arrDeptID.Contains(c.OrgID)).Select(c => c.S_A_User)).Distinct().ToList(); foreach (S_A_User item in list) { S_S_MsgReceiver receiver = listReceiver.Find(c => c.UserID == item.ID); if (receiver == null) { receiver = new S_S_MsgReceiver(); receiver.ID = FormulaHelper.CreateGuid(); receiver.MsgBodyID = msg.ID; receiver.UserID = item.ID; receiver.UserName = item.Name; listReceiver.Add(receiver); } } } foreach (S_S_MsgReceiver item in listReceiver) { entities.Set <S_S_MsgReceiver>().Add(item); } return(base.JsonSave <S_S_MsgBody>(msg)); }
private void SaveReceiver(string msgBodyId, string userId) { var entitie = FormulaHelper.GetEntities <BaseEntities>(); S_S_MsgReceiver receiver = new S_S_MsgReceiver(); receiver.ID = FormulaHelper.CreateGuid(); receiver.MsgBodyID = msgBodyId; receiver.UserID = userId; receiver.UserName = FormulaHelper.GetUserInfoByID(userId).UserName; receiver.IsDeleted = "0"; entitie.Set <S_S_MsgReceiver>().Add(receiver); entitie.SaveChanges(); }
public override JsonResult Save() { var msg = UpdateEntity <S_S_MsgBody>(); var user = FormulaHelper.GetUserInfo(); msg.SenderID = user.UserID; msg.SenderName = user.UserName; msg.SendTime = DateTime.Now; msg.Content = Request["content"]; msg.ContentText = RemoveImg(Request["contenttext"]); if (msg.Content.Length > 2000) { throw new BusinessException("消息长度不能超过2000个字符!"); } List <S_S_MsgReceiver> listReceiver = new List <S_S_MsgReceiver>(); if (!string.IsNullOrEmpty(msg.ReceiverIDs) && !string.IsNullOrEmpty(msg.ReceiverNames)) { string[] receiverIDs = msg.ReceiverIDs.Split(','); string[] receiverNames = msg.ReceiverNames.Split(','); for (int i = 0; i < receiverIDs.Length; i++) { S_S_MsgReceiver receiver = new S_S_MsgReceiver(); receiver.ID = FormulaHelper.CreateGuid(); receiver.MsgBodyID = msg.ID; receiver.UserID = receiverIDs[i]; receiver.UserName = receiverNames[i]; listReceiver.Add(receiver); } } if (!string.IsNullOrEmpty(msg.ReceiverDeptIDs) && string.IsNullOrEmpty(msg.ReceiverRoleIDs)) { string[] arrDeptID = msg.ReceiverDeptIDs.Split(','); List <S_A_User> list = base.DataBaseFilter <S_A_User>(entities.Set <S_A__OrgUser>().Where(c => arrDeptID.Contains(c.OrgID)).Select(c => c.S_A_User)).Distinct().ToList(); foreach (S_A_User item in list) { S_S_MsgReceiver receiver = listReceiver.Find(c => c.UserID == item.ID); if (receiver == null) { receiver = new S_S_MsgReceiver(); receiver.ID = FormulaHelper.CreateGuid(); receiver.MsgBodyID = msg.ID; receiver.UserID = item.ID; receiver.UserName = item.Name; listReceiver.Add(receiver); } } } else if (!string.IsNullOrEmpty(msg.ReceiverDeptIDs) || !string.IsNullOrEmpty(msg.ReceiverRoleIDs)) { IRoleService roleService = FormulaHelper.GetService <IRoleService>(); IUserService userService = FormulaHelper.GetService <IUserService>(); string userIds = roleService.GetUserIDsInRoles(msg.ReceiverRoleIDs, msg.ReceiverDeptIDs); string userNames = userService.GetUserNames(userIds); var userIdArr = userIds.Split(','); var userNameArr = userNames.Split(','); for (int i = 0; i < userIdArr.Length; i++) { var userId = userIdArr[i]; if (userId == "") { continue; } S_S_MsgReceiver receiver = listReceiver.Find(c => c.UserID == userId); if (receiver == null) { receiver = new S_S_MsgReceiver(); receiver.ID = FormulaHelper.CreateGuid(); receiver.MsgBodyID = msg.ID; receiver.UserID = userId; receiver.UserName = userNameArr[i]; listReceiver.Add(receiver); } } } foreach (S_S_MsgReceiver item in listReceiver) { entities.Set <S_S_MsgReceiver>().Add(item); } return(base.JsonSave <S_S_MsgBody>(msg)); }
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)); } }