Exemple #1
0
        public void GetForumThread()
        {
            int    forumThreadID  = ProviderBase.Framework.Utility.GetFormValue <int>("ID", 0);
            int    pageCurrent    = ProviderBase.Framework.Utility.GetFormValue <int>("PageCurrent", 1);
            int    pageSize       = ProviderBase.Framework.Utility.GetFormValue <int>("PageSize", 10);
            string templatePrefix = ProviderBase.Framework.Utility.GetFormValue <string>("TemplatePrefix", "");
            string templateName   = "ForumThreadRepeat.htm";
            string templateFinal  = "";

            if (string.IsNullOrEmpty(templatePrefix))
            {
                templatePrefix = this.Website.WebsiteTemplatePrefix;
            }

            if (forumThreadID > 0)
            {
                ForumThread forumThreadItem     = null;
                DataProviderResultFilter paging = null;

                paging = new DataProviderResultFilter();
                paging.SetPaging(typeof(ForumArea), typeof(List <ForumThread>), pageCurrent, pageSize);

                forumThreadItem = DataProvider.SelectSingleFull(new ForumThread()
                {
                    ForumThreadID = forumThreadID
                }, this.Website.WebsiteConnection.ConnectionString, paging);

                if (forumThreadItem?.ForumThreadID > 0)
                {
                    ForumArea forumAreaItem = null;

                    forumAreaItem = ProviderBase.Data.Providers.DataProvider.SelectSingle <ForumArea>(new ForumArea()
                    {
                        ForumAreaID = forumThreadItem.ForumAreaID
                    }, this.Website.WebsiteConnection.ConnectionString);

                    if (forumAreaItem?.ForumAreaID > 0)
                    {
                        ForumGroupUserRoleLink forumGroupUserRoleLink = null;

                        forumGroupUserRoleLink = ProviderBase.Data.Providers.DataProvider.SelectSingleUsingDefault <ForumGroupUserRoleLink>(new ForumGroupUserRoleLink()
                        {
                            UserRoleTypeID = this.User.UserRoleTypeID,
                            ForumGroupID   = forumAreaItem.ForumGroupID
                        }, this.Website.WebsiteConnection.ConnectionString, "UserRoleTypeID", "ForumGroupID");

                        if (forumGroupUserRoleLink?.UserRoleLevelID > 0)
                        {
                            TemplateFile    templateFileTemp = null;
                            ForumThreadView forumThreadView  = null;

                            templateFileTemp = new TemplateFile(templatePrefix + templateName, this.Website.WebsiteTemplateFolder);

                            forumThreadItem.PageSize = pageSize; // Override page size so BindTemplateFileContentRepeat is correct

                            templateFileTemp.BindTemplateFileContent(forumAreaItem, "FORUMAREA");
                            templateFileTemp.BindTemplateFileContent(forumThreadItem);
                            templateFileTemp.BindTemplateFileContentRepeat(forumThreadItem);

                            if (forumThreadItem.ThreadMessageList?.Count > 0)
                            {
                                PagingItem pagingItem = null;

                                pagingItem = ProviderBase.Data.Utility.XMLDeseralize <PagingItem>(this.Context.Server.MapPath(@"/Resource/XML/") + "Conquest/ConquestGamingPaging.xml");

                                templateFileTemp.BindTemplateFileContentRepeatSingle("$PAGING$", Utility.GeneratePaging(pagingItem, forumThreadItem.ThreadMessageList[0].PageCurrent, forumThreadItem.ThreadMessageList[0].PageTotal));
                                templateFileTemp.BindTemplateFileContentRepeatSingle("$PAGESIZE$", pageSize);

                                foreach (ForumThreadMessage forumThreadMessageItem in forumThreadItem.ThreadMessageList)
                                {
                                    CharacterUser characterUser = null;

                                    characterUser = DataProvider.SelectSingleFull <CharacterUser>(new CharacterUser()
                                    {
                                        UserID = forumThreadMessageItem.CharacterUserID
                                    }, this.Website.WebsiteConnection.ConnectionString);

                                    templateFileTemp.BindTemplateFileContentRepeatItem(new List <object>()
                                    {
                                        forumThreadMessageItem, characterUser
                                    });
                                }

                                forumThreadView = new ForumThreadView();
                                forumThreadView.CharacterUserID   = this.User.UserID;
                                forumThreadView.ForumThreadID     = forumThreadID;
                                forumThreadView.CreateDate        = DateTime.Now;
                                forumThreadView.ForumThreadViewID = DataProvider.Insert <ForumThreadView>(forumThreadView, this.Website.WebsiteConnection.ConnectionString);
                            }
                            else
                            {
                                templateFileTemp.BindTemplateFileContentSingle("$PAGING$", "");
                            }

                            templateFinal += templateFileTemp.TemplateFinalise(this.User);

                            this.AjaxResult.Data.Add(templateFinal);
                            this.AjaxResult.Message = "Get forum thread success";
                            this.AjaxResult.Status  = AjaxResultStatus.Success;
                        }
                        else
                        {
                            this.AjaxResult.Redirect = Utility.GetRedirect(this.Context, RedirectReason.InvalidPermission);
                            this.AjaxResult.Status   = AjaxResultStatus.Redirect;
                        }
                    }
                }
                else
                {
                    this.AjaxResult.Message = "No forum thread found";
                    this.AjaxResult.Status  = AjaxResultStatus.Failed;
                }
            }
            else
            {
                this.AjaxResult.Message = "No forum thread ID supplied";
                this.AjaxResult.Status  = AjaxResultStatus.Failed;
            }
        }