Beispiel #1
0
        public ThreadsViewModel GetThreadsViewModel(Page page, long tenantId, long?userId, long elementId, int?pageIndex)
        {
            int           threadsPerPage = _forumConfigurationService.ThreadsPerPage;
            ForumThreads  threads        = _forumService.ListThreads(tenantId, elementId, pageIndex == null ? 0 : (int)pageIndex - 1, threadsPerPage);
            UrlParameters urlParameters  = new UrlParameters {
                RouteName = "ReadPage", RouteValues = new { pageid = page.PageId, description = page.Name }
            };
            ThreadsViewModel viewModel = new ThreadsViewModel
            {
                Threads = threads,
                Pager   = new Pager {
                    PageIndex = pageIndex == null ? 1 : (int)pageIndex, Total = threads.Total, PageSize = threadsPerPage, UrlParameters = urlParameters
                },
                PageCounts       = new List <int>(),
                ShowCreateThread = (userId == null) || _forumAuthorizer.UserCanCreateThread(tenantId, elementId, userId.Value)
            };

            if (viewModel.ShowCreateThread)
            {
                viewModel.CreateThreadUrl = GetCreateThreadUrl(page, userId.HasValue);
            }
            int postsPerPage = _forumConfigurationService.PostsPerPage;

            foreach (ForumThreadExtended threadExtended in threads)
            {
                viewModel.PageCounts.Add(postsPerPage == 0 ? 1 : ((threadExtended.Thread.Replies - 1) / postsPerPage) + 1);
            }
            return(viewModel);
        }
Beispiel #2
0
        public ForumThreads ListTaggedLatestThreads(long tenantId, long?pageId, int pageSize, IList <Tag> tags, bool recursive, IUnitOfWork unitOfWork = null)
        {
            TagCollection tagCollection = new TagCollection();

            foreach (Tag tag in tags)
            {
                tagCollection.Add(tag);
            }
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                int          pageIndex = 0;
                ForumThreads threads   = new ForumThreads();
                string       sql       = _sqlManager.GetSql(recursive ? "Sql.ListTaggedLatestThreadsRecursive.sql" : "Sql.ListTaggedLatestThreads.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.AddParameter("@PageId", FieldType.BigInt, pageId ?? (object)DBNull.Value);
                dbm.AddParameter("@PageIndex", FieldType.Int, pageIndex);
                dbm.AddParameter("@PageSize", FieldType.Int, pageSize);
                dbm.AddTypedParameter("@Tags", FieldType.Structured, tagCollection.Count == 0 ? null : tagCollection, "cms.TagTableType");
                dbm.ExecuteReader();
                while (dbm.Read())
                {
                    threads.Add(new ForumThreadExtended
                    {
                        Thread         = GetThread(dbm),
                        User           = GetUser(dbm),
                        LastPostUserId = dbm.DataReaderValue("LastPostUserId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("LastPostUserId"),
                        LastPostUser   = dbm.DataReaderValue("LastPostAlias") == DBNull.Value ? null : GetUser(dbm, "LastPost"),
                        PageId         = (long)dbm.DataReaderValue("PageId")
                    });
                }
                return(threads);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Beispiel #3
0
        public ForumThreads ListLatestThreads(long tenantId, long?pageId, int pageSize, bool recursive, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                int          pageIndex = 0;
                ForumThreads threads   = new ForumThreads();
                string       sql       = _sqlManager.GetSql(recursive ? "Sql.ListLatestThreadsRecursive.sql" : "Sql.ListLatestThreads.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.AddParameter("@PageId", FieldType.BigInt, pageId ?? (object)DBNull.Value);
                dbm.AddParameter("@PageIndex", FieldType.Int, pageIndex);
                dbm.AddParameter("@PageSize", FieldType.Int, pageSize);
                dbm.ExecuteReader();
                while (dbm.Read())
                {
                    threads.Add(new ForumThreadExtended
                    {
                        Thread         = GetThread(dbm),
                        User           = GetUser(dbm),
                        LastPostUserId = dbm.DataReaderValue("LastPostUserId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("LastPostUserId"),
                        LastPostUser   = dbm.DataReaderValue("LastPostAlias") == DBNull.Value ? null : GetUser(dbm, "LastPost"),
                        PageId         = (long)dbm.DataReaderValue("PageId")
                    });
                }
                return(threads);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Beispiel #4
0
        public ForumThreads ListThreads(long tenantId, long elementId, int pageIndex, int pageSize, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                string sql = _sqlManager.GetSql("Sql.ListForumThreads.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, elementId);
                dbm.AddParameter("@PageIndex", FieldType.Int, pageIndex);
                dbm.AddParameter("@PageSize", FieldType.Int, pageSize);
                dbm.ExecuteReader();
                ForumThreads threads = new ForumThreads();
                while (dbm.Read())
                {
                    threads.Add(new ForumThreadExtended
                    {
                        Thread         = GetThread(dbm),
                        User           = GetUser(dbm),
                        LastPostUserId = dbm.DataReaderValue("LastPostUserId") == DBNull.Value ? null : (long?)dbm.DataReaderValue("LastPostUserId"),
                        LastPostUser   = dbm.DataReaderValue("LastPostAlias") == DBNull.Value ? null : GetUser(dbm, "LastPost")
                    });
                }
                dbm.Read();
                threads.Total = (int)dbm.DataReaderValue("ThreadCount");
                return(threads);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }