Ejemplo n.º 1
0
        public static SimpleDataSet MapTopicToSimpleDataIndexItem(ReadOnlyTopic topic, SimpleDataSet simpleDataSet, int id, string indexType)
        {
            //First generate the accumulated comment text:
            string commentText = string.Empty;
            foreach (var currentComment in topic.Comments)
                commentText += currentComment.Body;

            var body = umbraco.library.StripHtml(topic.Body + commentText);

            simpleDataSet.NodeDefinition.NodeId = id;
            simpleDataSet.NodeDefinition.Type = indexType;

            simpleDataSet.RowData.Add("body", body);
            if (!string.IsNullOrEmpty(commentText))
            {
                simpleDataSet.RowData.Add("comments", commentText);
            }
            simpleDataSet.RowData.Add("nodeName", topic.Title);
            simpleDataSet.RowData.Add("updateDate", topic.Updated.ToString("yyyy-MM-dd HH:mm:ss"));
            simpleDataSet.RowData.Add("nodeTypeAlias", "forum");

            simpleDataSet.RowData.Add("urlName", topic.UrlName);

            simpleDataSet.RowData.Add("createDate", topic.Created.ToString("yyyy-MM-dd HH:mm:ss"));

            simpleDataSet.RowData.Add("latestCommentId", topic.LatestComment.ToString());
            simpleDataSet.RowData.Add("latestReplyAuthorId", topic.LatestReplyAuthor.ToString());
            if (!string.IsNullOrEmpty(topic.LastReplyAuthorName))
            {
                simpleDataSet.RowData.Add("latestReplyAuthorName", topic.LastReplyAuthorName);
            }

            simpleDataSet.RowData.Add("authorId", topic.MemberId.ToString());
            if (!string.IsNullOrEmpty(topic.AuthorName))
            {
                simpleDataSet.RowData.Add("authorName", topic.AuthorName);
            }

            simpleDataSet.RowData.Add("parentId", topic.ParentId.ToString());
            simpleDataSet.RowData.Add("replies", topic.Replies.ToString());

            simpleDataSet.RowData.Add("locked", topic.Locked.ToString());
            simpleDataSet.RowData.Add("solved", topic.Answer.ToString());

            simpleDataSet.RowData.Add("version", topic.Version.ToString());

            return simpleDataSet;
        }
Ejemplo n.º 2
0
        public ReadOnlyTopic Map(ReadOnlyTopic topic, ReadOnlyComment comment)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (topic == null)
                return _current;

            // Is this the same Topic as the current one we're processing
            if (_current != null && _current.Id == topic.Id)
            {
                // Yes, just add this Comment to the current Topic's collection of Comments
                if (comment.Id > 0)
                {
                    _current.Comments.Add(comment);
                }

                // Return null to indicate we're not done with this Topic yet
                return null;
            }

            // This is a different Topic to the current one, or this is the
            // first time through and we don't have an Topic yet

            // Save the current Topic
            var prev = _current;

            // Setup the new current topic
            _current = topic;
            _current.Comments = new List<ReadOnlyComment>();
            if (comment.Id > 0)
            {
                _current.Comments.Add(comment);
            }

            // Return the now populated previous author (or null if first time through)
            return prev;
        }