/// <summary> /// 获取当前loginUser和relativeUser之间的PM内容 /// </summary> /// <param name="relativeUserId"></param> /// <param name="lastTime"></param> /// <param name="page"></param> /// <returns></returns> public IEnumerable <object> Get([FromUri] string relativeUserId, [FromUri] DateTime?lastTime, [FromUri] int?page) { IUserDao dao = _memberShipFactory.CreateUserDao(); User currentUser = OrnamentContext.MemberShip.CurrentUser(); User receiverUser = dao.Get(relativeUserId); IPersonalMessageDao msgDao = _factory.PersonalMessageDao; var result = new List <object>(); foreach (PersonalMessage a in msgDao.GetChat(currentUser, receiverUser, lastTime, page ?? 0, 20)) { a.HasRead(currentUser, msgDao); result.Add(new { id = a.Id, publisher = a.Publisher.Name, receiver = a.Receiver.Name, content = a.Content, createTime = a.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }); } return(result); }
public void Create(IPersonalMessageDao dao, User publisher, User receiver) { var message = new PersonalMessage(publisher) { Content = Content, Receiver = receiver }; dao.SaveOrUpdate(message); }
public void Create(IPersonalMessageDao dao, User publisher, User receiver) { var message = new PersonalMessage(publisher) { Content = Content, Receiver = receiver }; dao.SaveOrUpdate(message); }
/// <summary> /// /// </summary> /// <param name="currentUser"></param> /// <param name="personalMessageDao"></param> public virtual void HasRead(User currentUser, IPersonalMessageDao personalMessageDao) { if (currentUser == null) { throw new ArgumentNullException("currentUser"); } if (personalMessageDao == null) { throw new ArgumentNullException("personalMessageDao"); } ReadStatus = Receiver.Id == currentUser.Id ? PersonalMessageStatus.Receiver : PersonalMessageStatus.Publisher; personalMessageDao.SaveOrUpdate(this); }
/// <summary> /// 至少有当Receiver和Publisher都要求删除的时候。db中才会真正删除 /// </summary> /// <param name="currentUser"></param> /// <param name="personalMessageDao"></param> public virtual void Delete(User currentUser, IPersonalMessageDao personalMessageDao) { if (currentUser == null) { throw new ArgumentNullException("currentUser"); } if (personalMessageDao == null) { throw new ArgumentNullException("personalMessageDao"); } if (Receiver.Id == currentUser.Id) { DeleteStatus |= PersonalMessageStatus.Receiver; } else { DeleteStatus |= PersonalMessageStatus.Publisher; } if (this.DeleteStatus.HasFlag(PersonalMessageStatus.Publisher) && this.DeleteStatus.HasFlag(PersonalMessageStatus.Receiver)) { personalMessageDao.Delete(this); } }