Latest Builds - Author List

Topics: Controls
Feb 22, 2012 at 9:45 AM

Good to see this control having a widget and that it now sorts alphabetically on user name. Just wondering if it might be useful to consider profile names (if there are any) when sorting alphabetically, the change required would be minimal.

private HtmlGenericControl BindAuthors()
        {
            if (Post.Posts.Count == 0)
            {
                var p = new HtmlGenericControl("p") { InnerHtml = labels.none };
                return p;
            }

            var ul = new HtmlGenericControl("ul") { ID = "authorlist" };

            IEnumerable<MembershipUser> users = Membership.GetAllUsers()
                .Cast<MembershipUser>()
                .ToList()
                .OrderBy(
                    a => 
                        {
                            string profileName = a.UserName;
                            AuthorProfile ap = AuthorProfile.GetProfile(a.UserName);
                            if (ap != null)
                            {
                                profileName = AuthorProfile.GetProfile(a.UserName).DisplayName;
                            }
                            return profileName;
                        });

            foreach (MembershipUser user in users)
            {
                var postCount = Post.GetPostsByAuthor(user.UserName).Count;
                if (postCount == 0)
                {
                    continue;
                }                

                var li = new HtmlGenericControl("li");

                string profileName = user.UserName;
                AuthorProfile ap = AuthorProfile.GetProfile(user.UserName);
                if (ap != null)
                {
                    profileName = AuthorProfile.GetProfile(user.UserName).DisplayName;
                }

                if (ShowRssIcon)
                {
                    var img = new HtmlImage
                        {
                            Src = string.Format("{0}pics/rssButton.png", Utils.RelativeWebRoot),
                            Alt = string.Format("RSS feed for {0}", profileName)
                        };
                    img.Attributes["class"] = "rssButton";

                    var feedAnchor = new HtmlAnchor
                        {
                            HRef =
                                string.Format("{0}syndication.axd?author={1}", Utils.RelativeWebRoot, Utils.RemoveIllegalCharacters(user.UserName))
                        };
                    feedAnchor.Attributes["rel"] = "nofollow";
                    feedAnchor.Controls.Add(img);

                    li.Controls.Add(feedAnchor);
                }

                var anc = new HtmlAnchor
                    {
                        HRef = string.Format("{0}author/{1}{2}", Utils.RelativeWebRoot, user.UserName, BlogConfig.FileExtension),
                        InnerHtml = string.Format("{0} ({1})", profileName, postCount),
                        Title = string.Format("Author: {0}", profileName)
                    };

                li.Controls.Add(anc);
                ul.Controls.Add(li);
            }

            return ul;
        }