protected void Page_Load(object sender, EventArgs e)
    {
        litError.Visible = false;
        try
        {
            //If you loaded multiple hosts, like say for each website, replace the string with a retrieval method of your choice.
            //Example, if you loaded by site name you could get the current site name.
            host = Host.Get("default");

            int forumId;
            if (Request["f"] == null || !Int32.TryParse(Request["f"], out forumId))
            {
                throw new ArgumentException("Forum Id was missing or invalid");
            }

            lnkForumList.Text           = "Forums";
            lnkForumList.NavigateUrl    = "/community/forums";
            lnkThreadCreate.Text        = "New Post";
            lnkThreadCreate.NavigateUrl = string.Format("/community/forums/create?f={0}", forumId);

            var     endpointForumShow = string.Format("forums/{0}.json", forumId);
            dynamic responseForumShow = host.GetToDynamic(2, endpointForumShow);

            litForumName.Text = responseForumShow.Forum.Name;

            var options = new NameValueCollection();
            options.Add("PageSize", "50");
            options.Add("PageIndex", "0");
            options.Add("SortBy", "LastPost");
            options.Add("SortOrder", "Descending");

            var endpointThreadList = string.Format("forums/{0}/threads.json?{1}", forumId,
                                                   String.Join("&", options.AllKeys.Select(a => a + "=" + HttpUtility.UrlEncode(options[a]))));
            dynamic responseThreadList = host.GetToDynamic(2, endpointThreadList);
            rptForumThreads.DataSource = responseThreadList.Threads;
            rptForumThreads.DataBind();
        }
        catch (Exception ex)
        {
            litError.Text    = ex.Message + "<br/><pre>" + ex.StackTrace + "</pre>";
            litError.Visible = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        litError.Visible = false;
        try
        {
            //If you loaded multiple hosts, like say for each website, replace the string with a retrieval method of your choice.
            //Example, if you loaded by site name you could get the current site name.
            host = Host.Get("default");

            int threadId;
            if (Request["t"] == null || !Int32.TryParse(Request["t"], out threadId))
            {
                throw new ArgumentException("Thread Id was missing or invalid");
            }

            var     endpointThreadShow = string.Format("forums/threads/{0}.json", threadId);
            dynamic responseThreadShow = host.GetToDynamic(2, endpointThreadShow);
            litThreadSubject.Text          = responseThreadShow.Thread.Subject;
            lblThreadAuthorName.Text       = responseThreadShow.Thread.Author.DisplayName;
            imgThreadAuthorAvatar.ImageUrl = responseThreadShow.Thread.Author.AvatarUrl;
            lblThreadPostDate.Text         = responseThreadShow.Thread.LatestPostDate;
            litThreadBody.Text             = responseThreadShow.Thread.Body;

            var options = new NameValueCollection();
            options.Add("PageSize", "50");
            options.Add("PageIndex", "0");
            options.Add("SortBy", "PostDate");
            options.Add("SortOrder", "Ascending");

            var     endpointForumShow = string.Format("forums/{0}.json", responseThreadShow.Thread.ForumId);
            dynamic responseForumShow = host.GetToDynamic(2, endpointForumShow);

            lnkForum.Text        = responseForumShow.Forum.Name;
            lnkForum.NavigateUrl = string.Format("/community/forum?f={0}", responseForumShow.Forum.Id);

            var endpoint = string.Format("forums/{0}/threads/{1}/replies.json?{2}", responseForumShow.Forum.Id, threadId,
                                         String.Join("&", options.AllKeys.Select(a => a + "=" + HttpUtility.UrlEncode(options[a]))));
            dynamic response = host.GetToDynamic(2, endpoint);
            if (response.Errors.Count > 0)
            {
                throw new Exception(response.Errors[0].Message.ToString());
            }
            rptReplies.DataSource = response.Replies;
            rptReplies.DataBind();

            var isQA               = responseThreadShow.Thread.ThreadType == "QuestionAndAnswer";
            var hasAnswer          = responseThreadShow.Thread.AnswerCount != null && responseThreadShow.Thread.AnswerCount > 0;
            var hasSuggestedAnswer = responseThreadShow.Thread.SuggestedAnswerCount != null && responseThreadShow.Thread.SuggestedAnswerCount > 0;

            if (isQA)
            {
                if (hasAnswer)
                {
                    litStatus.Visible = true;
                    litStatus.Text    = "<div class=\"rounded thread-answer-status bg-success\"><p>This thread has verified answers</p></div>";
                }
                else if (hasSuggestedAnswer)
                {
                    litStatus.Visible = true;
                    litStatus.Text    = "<div class=\"rounded thread-answer-status bg-warning\"><p>This thread has suggested answers</p></div>";
                }
            }
        }
        catch (Exception ex)
        {
            litError.Text    = ex.Message + "<br/><pre>" + ex.StackTrace + "</pre>";
            litError.Visible = true;
        }
    }