Пример #1
0
 public bool Read(Contact reader)
 {
     if (this.Recipient.ID.Equals(reader.ID) && this.State == MessageState.Unread)
     {
         this.State = MessageState.Read;
         return true;
     }
     return false;
 }
Пример #2
0
 public Message(string title, string content, Contact sender, Contact recipient)
 {
     if (string.IsNullOrEmpty(title))
     {
         throw new CustomMessageException("title can't be null");
     }
     if (title.Length > 50)
     {
         throw new CustomMessageException("主题长度不能超过50");
     }
     if (string.IsNullOrEmpty(content))
     {
         throw new CustomMessageException("content can't be null");
     }
     if (content.Length > 20000)
     {
         throw new CustomMessageException("内容过长");
     }
     if (sender == null)
     {
         throw new CustomMessageException("sender can't be null");
     }
     if (recipient == null)
     {
         throw new CustomMessageException("recipient can't be null");
     }
     if (sender.ID == recipient.ID)
     {
         throw new CustomMessageException("发件人和收件人不能为同一人");
     }
     this.Title = title;
     this.Content = MarkDownHelper.MarkDownTransform(content);
     this.OriginalContent = content.Replace("\n", "<br />");
     this.SendTime = DateTime.Now;
     this.IP = Util.GetUserIpAddress();
     this.State = MessageState.Unread;
     if (sender.ID == 0 || sender.ID == 35695)
     {
         this.Type = MessageType.Notice;
     }
     else
     {
         this.Type = MessageType.Personal;
     }
     this.DisplayType = MessageDisplayType.OutboxAndInbox;
     this.Sender = sender;
     this.Recipient = recipient;
 }
Пример #3
0
 public bool CanRead(Contact reader)
 {
     if (this.Sender.ID == reader.ID)
     {
         if (this.DisplayType == MessageDisplayType.Outbox || this.DisplayType == MessageDisplayType.OutboxAndInbox)
         {
             return true;
         }
     }
     else if (this.Recipient.ID == reader.ID)
     {
         if (this.DisplayType == MessageDisplayType.Inbox || this.DisplayType == MessageDisplayType.OutboxAndInbox)
         {
             return true;
         }
     }
     return false;
 }
Пример #4
0
 public void DisposeMessageByReader(Contact reader)
 {
     // to do...
     if (this.Sender.ID == reader.ID)
     {
         if (this.DisplayType == MessageDisplayType.Outbox)
         {
             this.DisplayType = MessageDisplayType.NoOutboxAndInbox;
         }
         else if (this.DisplayType == MessageDisplayType.OutboxAndInbox)
         {
             this.DisplayType = MessageDisplayType.Inbox;
         }
     }
     else if (this.Recipient.ID == reader.ID)
     {
         if (this.DisplayType == MessageDisplayType.Inbox)
         {
             this.DisplayType = MessageDisplayType.NoOutboxAndInbox;
         }
         else if (this.DisplayType == MessageDisplayType.OutboxAndInbox)
         {
             this.DisplayType = MessageDisplayType.Outbox;
         }
     }
 }