Exemplo n.º 1
0
        public ForumPosts ListPosts(long tenantId, long elementId, long threadId, int pageIndex, int pageSize, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                string sql = _sqlManager.GetSql("Sql.ListForumThreadPosts.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, elementId);
                dbm.AddParameter("@ThreadId", FieldType.BigInt, threadId);
                dbm.AddParameter("@PageIndex", FieldType.Int, pageIndex);
                dbm.AddParameter("@PageSize", FieldType.Int, pageSize);
                dbm.ExecuteReader();
                ForumPosts posts = new ForumPosts();
                while (dbm.Read())
                {
                    posts.Add(new ForumPostAndUser
                    {
                        Post = GetPost(dbm),
                        User = GetUser(dbm)
                    });
                }
                dbm.Read();
                posts.Total = (int)dbm.DataReaderValue("Replies");
                return(posts);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        public ThreadViewModel GetThreadViewModel(Page page, long tenantId, long?userId, long elementId, long threadId, int?pageIndex)
        {
            int           pageSize      = _forumConfigurationService.PostsPerPage;
            ForumPosts    posts         = _forumService.ListPosts(tenantId, elementId, threadId, pageIndex == null ? 0 : (int)pageIndex - 1, pageSize);
            UrlParameters urlParameters = new UrlParameters {
                RouteName = "ReadPage", RouteValues = new { pageid = page.PageId, description = page.Name, threadid = threadId, forumaction = "thread" }
            };
            ForumThreadAndUser   threadAndUser  = _forumService.GetThreadAndUser(tenantId, elementId, threadId);
            List <PostViewModel> postViewModels = new List <PostViewModel>();

            foreach (ForumPostAndUser postAndUser in posts)
            {
                PostViewModel postViewModel = new PostViewModel
                {
                    PostAndUser    = postAndUser,
                    ShowUpdatePost = (userId != null) && (userId.Value == postAndUser.Post.UserId || _authorizationService.UserInFunction(Functions.UpdatePageElements))
                };
                postViewModel.ReplyPostUrl = GetPostUrl(page, userId.HasValue, ForumAction.ReplyPost, threadAndUser.Thread, postAndUser.Post);
                postViewModel.QuotePostUrl = GetPostUrl(page, userId.HasValue, ForumAction.QuotePost, threadAndUser.Thread, postAndUser.Post);
                if (postViewModel.ShowUpdatePost)
                {
                    postViewModel.UpdatePostUrl = GetPostUrl(page, userId.HasValue, ForumAction.UpdatePost, threadAndUser.Thread, postAndUser.Post);
                }
                postViewModels.Add(postViewModel);
            }
            ThreadViewModel viewModel = new ThreadViewModel
            {
                PostViewModels = postViewModels,
                ThreadAndUser  = threadAndUser,
                Pager          = new Pager {
                    PageIndex = pageIndex == null ? 1 : (int)pageIndex, Total = posts.Total, PageSize = pageSize, UrlParameters = urlParameters
                },
                DisplayThreadDetails = pageIndex == null || pageIndex == 1,
                ShowUpdateThread     = (userId != null) && (userId.Value == threadAndUser.Thread.UserId || _authorizationService.UserInFunction(Functions.UpdatePageElements)),
                ShowDeleteThread     = (userId != null) && _authorizationService.UserInFunction(Functions.UpdatePageElements)
            };

            viewModel.ReplyThreadUrl = GetThreadUrl(page, userId.HasValue, ForumAction.ReplyThread, threadAndUser.Thread);
            viewModel.QuoteThreadUrl = GetThreadUrl(page, userId.HasValue, ForumAction.QuoteThread, threadAndUser.Thread);
            if (viewModel.ShowUpdateThread)
            {
                viewModel.UpdateThreadUrl = GetThreadUrl(page, userId.HasValue, ForumAction.UpdateThread, threadAndUser.Thread);
            }
            if (viewModel.ShowDeleteThread)
            {
                viewModel.DeleteThreadUrl = GetThreadUrl(page, userId.HasValue, ForumAction.DeleteThread, threadAndUser.Thread);
            }
            return(viewModel);
        }