public static async Task<bool> SaveOrNot(Message msg) { using(NoticeRepository noticeRepository = new NoticeRepository()) { bool result = true; try { if(msg.ID == 0) { switch(msg.MsgType) { case (int)NoticeType.Visitor_Add: case (int)NoticeType.Favorite_Add: result = !await noticeRepository.CheckNoticeExist(msg); break; default: break; } } } catch(Exception ex) { LogHelper.LogErrorAsync(typeof(NoticeHelper), ex); } return result; } }
public async Task<bool> CheckNoticeExist(Message input) { var item = await (from uc in context.Messages where uc.Receiver_uuid == input.Receiver_uuid && uc.RelationID_uuid == input.RelationID_uuid && uc.MsgType == input.MsgType select uc).FirstOrDefaultAsync(); if(item != null) return true; else return false; }
public async Task<long> SaveNotice(Message input) { if(input.ID == 0) { context.Messages.Add(input); } else if(context.Entry(input).State == EntityState.Detached) { RepositoryHelper.UpdateContextItem(context, input); } if(await context.SaveChangesAsync() > 0) return input.ID; else return 0; }
public static Message GetMessageType(NoticeMQ notice) { Message msg = new Message(); msg.ID = notice.Id; msg.Receiver_uuid = notice.Receiver_Uuid; //msg.SendTime = CommonHelper.FromUnixTime(Convert.ToDouble(notice.TimeStamp)); msg.SendTime = notice.TimeStamp; msg.Status = notice.status; msg.MsgType = (int)notice.MsgType; msg.MessageInfo = notice.PayLoad as string; msg.RelationID_uuid = notice.Relation_Uuid; msg.RelationID = notice.Relation_Id; return msg; }
public static async Task<bool> UpdateNoticeAddContact(Message m) { NoticeMQ obj = new NoticeMQ(); obj.Id = m.ID; obj.MsgType = NoticeType.Contact_Request; obj.Relation_Uuid = m.RelationID_uuid; obj.Receiver_Uuid = m.Receiver_uuid; obj.PayLoad = m.MessageInfo; obj.status = m.Status; //obj.TimeStamp = CommonHelper.ToUnixTime(m.SendTime); obj.TimeStamp = m.SendTime; return MQManager.SendMQ_TB<NoticeMQConfig>(obj); }