예제 #1
0
파일: DBOperate.cs 프로젝트: MM1314/QG
        /// <summary>
        /// 更新消息状态,写入发送记录
        /// </summary>
        /// <param name="msg"></param>
        public static void SaveMessageLog(MessageEntity msg, string sendType, string exception)
        {
            using (MSGEntities db = new MSGEntities())
            {
                MD_Message md = db.MD_Message.SingleOrDefault(o => o.ID == msg.ID);
                if (md == null)
                {
                    throw new Exception(string.Format("消息{0}不存在。", msg.ID));
                }
                md.IsSended = md.IsSended.Value || msg.IsSended;

                MD_MessageLog log = db.MD_MessageLog.SingleOrDefault(o => o.MessageID == msg.ID && o.SendType.Equals(sendType));
                if (log == null)
                {
                    log           = new MD_MessageLog();
                    log.ID        = Guid.NewGuid();
                    log.MessageID = msg.ID;
                    log.SendType  = sendType;

                    db.MD_MessageLog.AddObject(log);
                }

                log.IsSuccess = msg.IsSended;
                log.Exception = exception;
                log.SendTime  = DateTime.Now;


                db.SaveChanges();
            }
        }
예제 #2
0
파일: DBOperate.cs 프로젝트: MM1314/QG
        /// <summary>
        /// 批量更新消息状态 暂未启用
        /// </summary>
        /// <param name="messages"></param>
        public static void UpdateMessageStatus(List <MessageEntity> messages)
        {
            using (MSGEntities dbContext = new MSGEntities())
            {
                foreach (MessageEntity msg in messages)
                {
                    var record = dbContext.MD_Message.SingleOrDefault(o => o.ID == msg.ID);
                    if (record != null)
                    {
                        //已发送则保持状态
                        record.IsSended = record.IsSended.Value || msg.IsSended;
                    }
                }

                dbContext.SaveChanges();
            }
        }