public JsonResult SendMessage(string mes, string receiver, string receiverName, bool state) { if (GetUserId() == null) { return(Json(false)); } MIS_WebIM_Message model = new MIS_WebIM_Message() { Message = mes, Sender = GetUserId(), SenderTitle = GetUserTrueName(), receiver = receiver, receiverTitle = receiverName, State = state.ToString(), SendDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; string ErrorCol = string.Empty; if (messageBLL.CreateMessage(ref errors, model)) { //开关,从config配置此功能 LogHandler.WriteServiceLog(GetUserId(), "Id:" + model.Id, "成功", "创建", "WebIM发送消息"); return(Json(true)); } else { ErrorCol = errors.Error; if (!string.IsNullOrEmpty(ErrorCol)) { LogHandler.WriteServiceLog(GetUserId(), "Id:" + model.Id + ErrorCol, "失败", "创建", "WebIM发送消息"); //写入日志 } return(Json(false)); //提示插入失败 } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <MIS_WebIM_MessageModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { MIS_WebIM_Message entity = new MIS_WebIM_Message(); entity.Id = ResultHelper.NewId; entity.Message = model.Message; entity.Sender = model.Sender; entity.receiver = model.receiver; entity.State = model.State; entity.SendDt = model.SendDt; entity.receiverTitle = model.receiverTitle; db.MIS_WebIM_Message.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
/// <summary> /// 读取一个发送消息 /// </summary> /// <param name="id">消息ID</param> /// <returns></returns> public MIS_WebIM_Message GetMessageBySender(string id) { try { var entity = m_Rep.GetMessageBySender(id); if (entity == null) { return(null); } MIS_WebIM_Message model = new MIS_WebIM_Message(); model.Id = entity.Id; model.Message = entity.Message; model.Sender = entity.Sender; model.receiver = entity.receiver; model.State = entity.State; model.SendDt = entity.SendDt; model.SenderTitle = userRep.Find(a => a.KEY_Id == model.Sender).TrueName; model.receiverTitle = userRep.Find(a => a.KEY_Id == model.receiver).TrueName; return(model); } catch (Exception ex) { ExceptionHander.WriteException(ex); return(null); } }
/// <summary> /// 新增消息 /// </summary> /// <param name="validationErrors"></param> /// <param name="model">消息模型</param> /// <returns></returns> public bool CreateMessage(ref ValidationErrors validationErrors, MIS_WebIM_Message model) { try { if (m_Rep.CreateMessage(model.Message, model.Sender, model.receiver, model.receiverTitle) != 0) { return(true); } else { return(false); } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual MIS_WebIM_MessageModel GetById(object id) { if (IsExists(id)) { MIS_WebIM_Message entity = m_Rep.GetById(id); MIS_WebIM_MessageModel model = new MIS_WebIM_MessageModel(); model.Id = entity.Id; model.Message = entity.Message; model.Sender = entity.Sender; model.receiver = entity.receiver; model.State = entity.State; model.SendDt = entity.SendDt; model.receiverTitle = entity.receiverTitle; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(MIS_WebIM_MessageModel model) { ValidationErrors errors = new ValidationErrors(); try { MIS_WebIM_Message entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new MIS_WebIM_Message(); entity.Id = model.Id; entity.Message = model.Message; entity.Sender = model.Sender; entity.receiver = model.receiver; entity.State = model.State; entity.SendDt = model.SendDt; entity.receiverTitle = model.receiverTitle; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public virtual bool Edit(ref ValidationErrors errors, MIS_WebIM_MessageModel model) { try { MIS_WebIM_Message entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Message = model.Message; entity.Sender = model.Sender; entity.receiver = model.receiver; entity.State = model.State; entity.SendDt = model.SendDt; entity.receiverTitle = model.receiverTitle; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Create(ref ValidationErrors errors, MIS_WebIM_MessageModel model) { try { MIS_WebIM_Message entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new MIS_WebIM_Message(); entity.Id = model.Id; entity.Message = model.Message; entity.Sender = model.Sender; entity.receiver = model.receiver; entity.State = model.State; entity.SendDt = model.SendDt; entity.receiverTitle = model.receiverTitle; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }