/// <summary>
        /// Add a private message
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public PrivateMessage Add(PrivateMessage message)
        {
            // This is the message that the other user sees
            message = SanitizeMessage(message);
            message.DateSent = DateTime.UtcNow;
            message.IsSentMessage = false;

            var e = new PrivateMessageEventArgs { PrivateMessage = message };
            EventManager.Instance.FireBeforePrivateMessage(this, e);

            if (!e.Cancel)
            {
                message = _context.PrivateMessage.Add(message);

                // We create a sent message that sits in the users sent folder, this is 
                // so that if the receiver deletes the message - The sender still has a record of it.
                var sentMessage = new PrivateMessage
                {
                    IsSentMessage = true,
                    DateSent = message.DateSent,
                    Message = message.Message,
                    UserFrom = message.UserFrom,
                    UserTo = message.UserTo
                };

                _context.PrivateMessage.Add(sentMessage);

                EventManager.Instance.FireAfterPrivateMessage(this, new PrivateMessageEventArgs { PrivateMessage = message });
            }

            // Return the main message
            return message;
        }
示例#2
0
        public void FireBeforePrivateMessage(object sender, PrivateMessageEventArgs eventArgs)
        {
            var handler = BeforePrivateMessage;

            if (handler != null)
            {
                handler(this, eventArgs);
            }
        }
示例#3
0
        public void FireBeforePrivateMessage(object sender, PrivateMessageEventArgs eventArgs)
        {
            var handler = BeforePrivateMessage;

            if (handler != null)
            {
                handler(this, eventArgs);
            }
        }