/// <summary>
        /// Gets info about changed fields and other attributes for particular user (if available).
        /// </summary>
        private string GetChangedFieldsInfoForUser(
            [NotNull] EmailModelBase model,
            [NotNull] User user)
        {
            if (!(model is IEmailWithUpdatedFieldsInfo mailWithFields))
            {
                return("");
            }
            //Add project fields that user has right to view
            var accessArguments = mailWithFields.FieldsContainer.GetAccessArguments(user.UserId);

            IEnumerable <MarkdownString> fieldString = mailWithFields
                                                       .UpdatedFields
                                                       .Where(f => f.HasViewAccess(accessArguments))
                                                       .Select(updatedField =>
                                                               new MarkdownString(
                                                                   $@"__**{updatedField.Field.FieldName}:**__
{MarkdownTransformations.HighlightDiffPlaceholder(updatedField.DisplayString, updatedField.PreviousDisplayString).Contents}"));

            //Add info about other changed atttributes (no access rights validation)
            IEnumerable <MarkdownString> otherAttributesStrings = mailWithFields
                                                                  .OtherChangedAttributes
                                                                  .Select(changedAttribute => new MarkdownString(
                                                                              $@"__**{changedAttribute.Key}:**__
{MarkdownTransformations.HighlightDiffPlaceholder(changedAttribute.Value.DisplayString, changedAttribute.Value.PreviousDisplayString).Contents}"));

            return(string.Join(
                       "\n\n",
                       otherAttributesStrings
                       .Union(fieldString)
                       .Select(x => x.ToHtmlString())));
        }
示例#2
0
        private static async Task <string> GetRenderableContent(
            IHtmlHelper helper,
            PostWithRelatedPostStubs post,
            Post previousPostIfAny,
            Post nextPostIfAny,
            bool includeTitle,
            bool includePostedDate,
            bool includeTags,
            IRetrievePostSlugs postSlugRetriever)
        {
            if (helper == null)
            {
                throw new ArgumentNullException(nameof(helper));
            }
            if (post == null)
            {
                throw new ArgumentNullException(nameof(post));
            }
            if (postSlugRetriever == null)
            {
                throw new ArgumentNullException(nameof(postSlugRetriever));
            }

            var markdownContent = await HandlePostLinks(
                helper,
                includeTitle?(await ReplaceFirstLineHashHeaderWithPostLink(post, postSlugRetriever)) : RemoveTitle(post.MarkdownContent),
                postSlugRetriever
                );

            var content = new StringBuilder();

            if (includePostedDate)
            {
                content.AppendFormat("<h3 class=\"PostDate\">{0}</h3>", post.Posted.ToString("d MMMM yyyy"));
            }
            content.Append(
                MarkdownTransformations.ToHtml(markdownContent)
                );
            if (includePostedDate)
            {
                content.AppendFormat("<p class=\"PostTime\">Posted at {0}</p>", post.Posted.ToString("HH:mm"));
            }
            if ((previousPostIfAny != null) || (nextPostIfAny != null))
            {
                content.Append("<div class=\"PreviousAndNext\">");
                if (previousPostIfAny != null)
                {
                    content.Append("<div class=\"Previous\">");
                    content.Append("<h3>Last time:</h3>");
                    content.Append(
                        helper.RenderedActionLink(previousPostIfAny.Title, "ArchiveBySlug", "ViewPost", new { previousPostIfAny.Slug }, new { @class = "Previous" })
                        );
                    content.Append("</div>");
                }
                if (nextPostIfAny != null)
                {
                    content.Append("<div class=\"Next\">");
                    content.Append("<h3>Next:</h3>");
                    content.Append(
                        helper.RenderedActionLink(nextPostIfAny.Title, "ArchiveBySlug", "ViewPost", new { nextPostIfAny.Slug }, new { @class = "Next" })
                        );
                    content.Append("</div>");
                }
                content.Append("</div>");
            }
            if (post.RelatedPosts.Any())
            {
                content.Append("<div class=\"Related\">");
                content.Append("<h3>You may also be interested in:</h3>");
                content.Append("<ul>");
                foreach (var relatedPost in post.RelatedPosts)
                {
                    content.AppendFormat(
                        "<li>{0}</li>",
                        helper.RenderedActionLink(relatedPost.Title, "ArchiveBySlug", "ViewPost", new { relatedPost.Slug }, null)
                        );
                }
                content.Append("</ul>");
                content.Append("</div>");
            }
            else if (post.AutoSuggestedRelatedPosts.Any())
            {
                // Only display the auto-suggested related posts if there are no manually-picked related posts
                content.Append("<div class=\"Related\">");
                content.AppendFormat(
                    "<h3>You may also be interested in (see {0} for information about how these are generated):</h3>",
                    helper.RenderedActionLink("here", "ArchiveBySlug", "ViewPost", new { Slug = "automating-suggested-related-posts-links-for-my-blog-posts" }, null)
                    );
                content.Append("<ul>");
                foreach (var relatedPost in post.AutoSuggestedRelatedPosts)
                {
                    content.AppendFormat(
                        "<li>{0}</li>",
                        helper.RenderedActionLink(relatedPost.Title, "ArchiveBySlug", "ViewPost", new { relatedPost.Slug }, null)
                        );
                }
                content.Append("</ul>");
                content.Append("</div>");
            }
            if (includeTags)
            {
                content.Append(GetTagLinksContent(helper, post.Tags));
            }
            return(content.ToString());
        }