/// <summary> /// 新增报警信息(内部调用) /// </summary> public ReturnItem <string> AddAlarmMessageInside(GetMessageInfoParameter parameter) { ReturnItem <string> r = new ReturnItem <string>(); using (UserEntities user = new UserEntities()) { try { //新增报警信息 U_Message message = new U_Message() { Type = parameter.Type, Tittle = parameter.Tittle, Text = parameter.Text, CreateTime = DateTime.Now }; user.U_Message.Add(message); user.SaveChanges(); //查询当前组织下用户id int OrgID = Convert.ToInt32(parameter.OrgID); var getuserinfo = user.U_UserOrganizationRel.Where(m => m.OrgID == OrgID).ToList(); List <string> userinfo = new List <string>(); foreach (var info in getuserinfo) { userinfo.Add(info.UserID.ToString()); } //新增用户消息关联表 var getinfo = user.U_Message.OrderByDescending(m => m.CreateTime).FirstOrDefault(); foreach (var item in userinfo) { U_UserMessageRel newrel = new U_UserMessageRel() { UserID = Convert.ToInt32(item), MessageID = getinfo.ID, Status = "0", CreateTime = DateTime.Now }; user.U_UserMessageRel.Add(newrel); } user.SaveChanges(); r.Msg = "消息新增成功"; r.Code = 0; } catch (Exception e) { r.Msg = "内部错误请重试"; r.Code = -1; r.Data = e.Message; log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace); } } return(r); }
/// <summary> /// 新增消息 /// </summary> public ReturnItem <RetMessageInfo> AddMessage(MessageInfoModel parameter) { ReturnItem <RetMessageInfo> r = new ReturnItem <RetMessageInfo>(); using (UserEntities user = new UserEntities()) { try { //新增消息 U_Message message = new U_Message() { Type = parameter.Type, Tittle = parameter.Tittle, Text = parameter.Text, CreateTime = DateTime.Now, CreateUserID = parameter.CreateUserID }; user.U_Message.Add(message); user.SaveChanges(); //新增用户消息关联表 var getinfo = user.U_Message.OrderByDescending(m => m.CreateTime).FirstOrDefault(); foreach (var item in parameter.UserID) { U_UserMessageRel newrel = new U_UserMessageRel() { UserID = Convert.ToInt32(item), MessageID = getinfo.ID, Status = "0", CreateTime = DateTime.Now, CreateUserID = parameter.CreateUserID }; user.U_UserMessageRel.Add(newrel); } user.SaveChanges(); r.Msg = "消息新增成功"; r.Code = 0; } catch (Exception e) { r.Msg = "内部错误请重试"; log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace); r.Code = -1; } } return(r); }