Exemplo n.º 1
0
        /// <summary>
        /// Gets the List of all message changes.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="messageId">
        /// The Message ID.
        /// </param>
        /// <param name="daysToClean">
        /// Days to clean.
        /// </param>
        /// <returns>
        /// Returns the List of all message changes.
        /// </returns>
        public static List <MessageHistoryTopic> List(
            this IRepository <MessageHistory> repository,
            [NotNull] int messageId,
            [NotNull] int daysToClean)
        {
            CodeContracts.VerifyNotNull(repository);

            repository.DeleteOlderThen(daysToClean);

            var list = repository.DbAccess.Execute(
                db =>
            {
                var expression = OrmLiteConfig.DialectProvider.SqlExpression <MessageHistory>();

                expression.LeftJoin <Message>((mh, m) => mh.MessageID == m.ID)
                .LeftJoin <Message, Topic>((m, t) => t.ID == m.TopicID)
                .LeftJoin <MessageHistory, User>((mh, u) => u.ID == mh.EditedBy)
                .Where <MessageHistory>(mh => mh.MessageID == messageId).OrderBy(mh => mh.Edited)
                .ThenBy(mh => mh.MessageID).Select <MessageHistory, Message, Topic, User>(
                    (mh, m, t, u) => new
                {
                    mh.EditReason,
                    mh.Edited,
                    mh.EditedBy,
                    mh.Flags,
                    mh.IP,
                    mh.IsModeratorChanged,
                    mh.MessageID,
                    mh.Message,
                    u.Name,
                    u.DisplayName,
                    u.UserStyle,
                    u.Suspended,
                    t.ForumID,
                    TopicID = t.ID,
                    Topic   = t.TopicName,
                    m.Posted,
                    MessageIP = m.IP
                });

                return(db.Connection
                       .Select <MessageHistoryTopic>(expression));
            });

            // Load Current Message
            var currentMessage = BoardContext.Current.GetRepository <Message>().GetMessage(messageId);

            var current = new MessageHistoryTopic
            {
                EditReason         = currentMessage.Item2.EditReason,
                Edited             = currentMessage.Item2.Edited.Value,
                EditedBy           = currentMessage.Item2.UserID,
                Flags              = currentMessage.Item2.Flags,
                IP                 = currentMessage.Item2.IP,
                IsModeratorChanged = currentMessage.Item2.IsModeratorChanged,
                MessageID          = currentMessage.Item2.ID,
                Message            = currentMessage.Item2.MessageText,
                Name               = currentMessage.Item3.Name,
                DisplayName        = currentMessage.Item3.DisplayName,
                UserStyle          = currentMessage.Item3.UserStyle,
                Suspended          = currentMessage.Item3.Suspended,
                ForumID            = currentMessage.Item1.ForumID,
                TopicID            = currentMessage.Item1.ID,
                Topic              = currentMessage.Item1.TopicName,
                Posted             = currentMessage.Item2.Posted,
                MessageIP          = currentMessage.Item2.IP
            };

            list.Add(current);

            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The get IP address.
        /// </summary>
        /// <param name="dataItem">
        /// The data item.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        protected string GetIpAddress(MessageHistoryTopic dataItem)
        {
            var ip = IPHelper.GetIp4Address(dataItem.IP);

            return(ip.IsSet() ? ip : IPHelper.GetIp4Address(dataItem.MessageIP));
        }