public bool ReplySiteMessage(Message parentMessage, Message replyMessage)
 {
     if (parentMessage.Sender == replyMessage.Sender && parentMessage.Recipient == replyMessage.Recipient)
     {
         if (parentMessage.DisplayType == MessageDisplayType.Outbox)
         {
             parentMessage.DisplayType = MessageDisplayType.OutboxAndInbox;
         }
         else
         {
             throw new CustomMessageException("消息已被您删除,无法回复");
         }
     }
     else if (parentMessage.Sender == replyMessage.Recipient && parentMessage.Recipient == replyMessage.Sender)
     {
         if (parentMessage.DisplayType == MessageDisplayType.Inbox)
         {
             parentMessage.DisplayType = MessageDisplayType.OutboxAndInbox;
         }
         else
         {
             throw new CustomMessageException("消息已被您删除,无法回复");
         }
     }
     else
     {
         throw new CustomMessageException("您不是收发件人,没有权限回复");
     }
     replyMessage.ParentMessage = parentMessage;
     return true;
 }
 public async Task<bool> SendMessage(Message message)
 {
     string title = message.Title;
     title = "[博客园短消息通知]" + title;
     string body = message.Recipient.DisplayName + ",您好!<br/><br/>";
     body += string.Format("<a href=\"{0}\">{1}</a>给您发了短消息:<br/>", "http://home.cnblogs.com/u/" + message.Sender.ID + "/", message.Sender.DisplayName);
     body += "<br/>";
     //body += message.Content.Replace("\n", "<br/>");
     body += message.Content;
     body += "<br/><br/>------------------------------------<br/>";
     body += string.Format("查看短消息:<a href=\"{0}\">{0}</a><br/>", "http://msg.cnblogs.com/msg/item/" + message.ID + "/");
     body += "这是系统自动通知邮件,不要直接回复该邮件。";
     await MailHelper.SendAsyncMail("*****@*****.**", await UserService.GetEmailByUserId(message.Recipient.ID), title, body);
     return true;
 }
        //ValidateSendingMessage(message)
        //ValidateSendingMessage.Validate(message)

        public async Task<bool> SendMessage(Message message)
        {
            IMessageRepository messageRepository = IocContainer.Resolver.Resolve<IMessageRepository>();
            if (message.Type == MessageType.Personal)
            {
                if (System.Web.HttpContext.Current != null)
                {
                    if (await messageRepository.GetMessageCountByIP(Util.GetUserIpAddress()) > 100)
                    {
                        throw new CustomMessageException("一天内只能发送100条短消息");
                    }
                }
                if (await messageRepository.GetOutboxCountBySender(message.Sender) > 20)
                {
                    throw new CustomMessageException("1小时内只能向20个不同的用户发送短消息");
                }
            }
            return true;
        }