Exemplo n.º 1
0
        protected void rptAllGroups_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //throw new NotImplementedException();
            if (e.Item != null)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    GroupCardModel  thisItem = ((GroupCardModel)e.Item.DataItem);
                    GroupJoinButton joinBtn  = e.FindControlAs <GroupJoinButton>("BtnJoin");
                    if (joinBtn != null)
                    {
                        if (e.Item.DataItem is GroupCardModel)
                        {
                            var id = thisItem.GroupID;
                            joinBtn.LoadState(id);
                        }
                    }
                    if (IsUserLoggedIn && !String.IsNullOrEmpty(CurrentMember.ScreenName))
                    {
                        HyperLink hrefImageLink = e.FindControlAs <HyperLink>("hrefImageLink");
                        if (hrefImageLink != null)
                        {
                            hrefImageLink.NavigateUrl = thisItem.GrpItem.GetUrl();
                        }

                        HyperLink hrefTitleLink = e.FindControlAs <HyperLink>("hrefTitleLink");
                        if (hrefImageLink != null)
                        {
                            hrefTitleLink.NavigateUrl = thisItem.GrpItem.GetUrl();
                        }
                    }
                    Image imgGroup = e.FindControlAs <Image>("imgGroup");
                    if (imgGroup != null)
                    {
                        imgGroup.ImageUrl = thisItem.ModeratorAvatarUrl ?? "http://placehold.it/150x85";
                    }
                    Literal litSkipThis = e.FindControlAs <Literal>("litSkipThis");
                    if (litSkipThis != null)
                    {
                        litSkipThis.Text = DictionaryConstants.SkipThisLabel; //Skip this
                    }
                    Literal litMembers = e.FindControlAs <Literal>("litMembers");
                    if (litMembers != null)
                    {
                        litMembers.Text = thisItem.NumOfMembers + DictionaryConstants.MembersLabel;
                    }
                    Literal litDiscussions = e.FindControlAs <Literal>("litDiscussions");
                    if (litDiscussions != null)
                    {
                        litDiscussions.Text = thisItem.NumOfDiscussions + DictionaryConstants.PostsLabel;
                    }
                }
            }
        }
        protected void rptMyGroups_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item != null)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    GroupCardModel  thisItem     = ((GroupCardModel)e.Item.DataItem);
                    ThreadModel     recentThread = null;
                    GroupJoinButton joinBtn      = e.FindControlAs <GroupJoinButton>("btnJoin");
                    if (joinBtn != null)
                    {
                        var id = thisItem.GroupID;
                        joinBtn.LoadState(id);
                    }

                    Literal litReplies = e.FindControlAs <Literal>("litRepliesLabel");
                    if (litReplies != null)
                    {
                        litReplies.Text = DictionaryConstants.RepliesLabel;
                    }
                    Literal litPostedByLabel = e.FindControlAs <Literal>("litPostedByLabel");
                    if (litPostedByLabel != null)
                    {
                        litPostedByLabel.Text = DictionaryConstants.PostedByLabel;
                    }

                    HyperLink hrefGroImageLink = e.FindControlAs <HyperLink>("hrefGroupImageLink");
                    if (hrefGroImageLink != null)
                    {
                        hrefGroImageLink.NavigateUrl = thisItem.GrpItem.GetUrl();
                    }

                    Image imgGrpImage = e.FindControlAs <Image>("imgGroupImage");
                    if (imgGrpImage != null)
                    {
                        imgGrpImage.ImageUrl = thisItem.ModeratorAvatarUrl ?? "http://placehold.it/190x107";
                    }

                    if (thisItem.Forums.Count > 0 && thisItem.Forums != null)
                    {
                        var recentThreadlist = (thisItem.Forums
                                                .Where(f => f.Threads.Count > 0 && f.Threads != null)
                                                .Select(x => x.Threads.Where(thread => thread != null)
                                                        .OrderByDescending(t => t.LastPostDate)).FirstOrDefault());


                        if (recentThreadlist != null)
                        {
                            recentThread = recentThreadlist.FirstOrDefault <ThreadModel>();
                        }

                        if (recentThread != null)
                        {
                            HyperLink hrefDiscussionLink = e.FindControlAs <HyperLink>("hrefDiscussionLink");
                            if (hrefDiscussionLink != null)
                            {
                                var threadItem = Threads.ConvertThreadtoSitecoreItem(recentThread.ForumID, recentThread.ThreadID);
                                if (threadItem != null)
                                {
                                    hrefDiscussionLink.NavigateUrl = threadItem.GetUrl();
                                }
                            }
                            Literal litDiscussionExcerpt = e.FindControlAs <Literal>("litDiscussionExcerpt");
                            if (litDiscussionExcerpt != null)
                            {
                                litDiscussionExcerpt.Text = recentThread.Subject;
                            }
                            Literal litNumReplies = e.FindControlAs <Literal>("litNumReplies");
                            if (litNumReplies != null)
                            {
                                litNumReplies.Text = recentThread.ReplyCount;
                            }

                            Literal litPostUserName = e.FindControlAs <Literal>("litPostUserName");
                            if (litPostUserName != null)
                            {
                                litPostUserName.Text = recentThread.LastPostUser;
                            }
                            HyperLink hrefPostUser = e.FindControlAs <HyperLink>("hrefPostUser");
                            if (hrefPostUser != null)
                            {
                                hrefPostUser.NavigateUrl = MembershipHelper.GetPublicProfileUrl(recentThread.LastPostUser);
                            }
                            Literal litPostTime = e.FindControlAs <Literal>("litPostTime");
                            if (litPostTime != null)
                            {
                                litPostTime.Text = recentThread.LastPostTime;
                            }
                        }
                    }
                }
            }
        }