Ejemplo n.º 1
0
        public ForumThreadAndUser GetThreadAndUser(long tenantId, long elementId, long threadId, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                ForumThreadAndUser thread = null;
                string             sql    = _sqlManager.GetSql("Sql.ReadForumThreadAndUser.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, elementId);
                dbm.AddParameter("@ThreadId", FieldType.BigInt, threadId);
                dbm.ExecuteReader();
                if (dbm.Read())
                {
                    thread = new ForumThreadAndUser
                    {
                        Thread = GetThread(dbm),
                        User   = GetUser(dbm)
                    };
                }
                return(thread);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        private Form GetQuoteThreadForm(string context)
        {
            // Get page, element and thread identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[1]);
            long     elementId = Convert.ToInt64(parts[2]);
            long     threadId  = Convert.ToInt64(parts[3]);

            // Get existing thread details
            ForumThreadAndUser forumThreadAndUser = _forumService.GetThreadAndUser(_authenticationService.TenantId, elementId, threadId);

            // Construct form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context
            };

            form.Fields.Add("message", new MultiLineTextField
            {
                Name                 = "message",
                Label                = ElementResource.ForumMessageLabel,
                Required             = true,
                RequiredErrorMessage = ElementResource.ForumMessageRequiredMessage,
                Rows                 = 10,
                Value                = _forumService.GetQuoteMessage(forumThreadAndUser.Thread.Message, forumThreadAndUser.User.Alias)
            });
            form.SubmitLabel = ElementResource.ForumQuoteThreadButtonLabel;

            // Return result
            return(form);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public IElementContent GetContent(IElementSettings settings, IPageContext pageContext, IUnitOfWork unitOfWork = null)
        {
            // Create content
            ForumContent content = new ForumContent
            {
                Page      = pageContext.Page,
                PageLinks = new List <IPageLink>()
            };

            // Get user details
            long tenantId = _authenticationService.TenantId;
            AuthenticatedUserInfo userInfo = _authenticationService.GetCurrentUser();
            long?userId = userInfo != null ? (long?)userInfo.User.UserId : null;

            // Get forum action
            string action;

            pageContext.Parameters.TryGetValue("forumaction", out action);

            // The forum action determines what information is retrieved and displayed
            switch (action)
            {
            case "createthread":
                content.PartialViewName = "ForumCreateThread";
                content.FormContext     = string.Format("{0}|{1}|{2}", action, pageContext.Page.PageId, settings.ElementId);
                break;

            case "updatethread":
                long updateThreadId = GetLong(pageContext.Parameters, "threadid").Value;
                ForumThreadAndUser forumThreadAndUser = _forumService.GetThreadAndUser(settings.TenantId, settings.ElementId, updateThreadId, unitOfWork);
                content.ThreadAndUser   = forumThreadAndUser;
                content.PartialViewName = "ForumUpdateThread";
                content.FormContext     = string.Format("{0}|{1}|{2}|{3}", action, pageContext.Page.PageId, settings.ElementId, updateThreadId);
                break;

            case "replythread":
            case "quotethread":
                long replyThreadId = GetLong(pageContext.Parameters, "threadid").Value;
                ForumThreadAndUser replyForumThreadAndUser = _forumService.GetThreadAndUser(settings.TenantId, settings.ElementId, replyThreadId, unitOfWork);
                content.ThreadAndUser   = replyForumThreadAndUser;
                content.PartialViewName = "ForumReplyThread";
                content.FormContext     = string.Format("{0}|{1}|{2}|{3}", action, pageContext.Page.PageId, settings.ElementId, replyThreadId);
                break;

            case "deletethread":
                long deleteThreadId = GetLong(pageContext.Parameters, "threadid").Value;
                ForumThreadAndUser deleteForumThreadAndUser = _forumService.GetThreadAndUser(settings.TenantId, settings.ElementId, deleteThreadId, unitOfWork);
                content.ThreadAndUser   = deleteForumThreadAndUser;
                content.PartialViewName = "ForumDeleteThread";
                content.FormContext     = string.Format("{0}|{1}|{2}|{3}", action, pageContext.Page.PageId, settings.ElementId, deleteThreadId);
                break;

            case "replypost":
            case "quotepost":
                long        actionThreadId = GetLong(pageContext.Parameters, "threadid").Value;
                long        actionPostId   = GetLong(pageContext.Parameters, "postid").Value;
                ForumThread forumThread    = _forumService.GetThread(settings.TenantId, settings.ElementId, actionThreadId, unitOfWork);
                content.Thread          = forumThread;
                content.PostAndUser     = _forumService.GetPostAndUser(settings.TenantId, settings.ElementId, actionThreadId, actionPostId, unitOfWork);
                content.PartialViewName = "ForumReplyPost";
                content.FormContext     = string.Format("{0}|{1}|{2}|{3}|{4}", action, pageContext.Page.PageId, settings.ElementId, actionThreadId, actionPostId);
                break;

            case "updatepost":
                long        updatePostThreadId    = GetLong(pageContext.Parameters, "threadid").Value;
                long        updatePostPostId      = GetLong(pageContext.Parameters, "postid").Value;
                ForumThread updatePostForumThread = _forumService.GetThread(settings.TenantId, settings.ElementId, updatePostThreadId, unitOfWork);
                content.Thread          = updatePostForumThread;
                content.PostAndUser     = _forumService.GetPostAndUser(settings.TenantId, settings.ElementId, updatePostThreadId, updatePostPostId, unitOfWork);
                content.PartialViewName = "ForumUpdatePost";
                content.FormContext     = string.Format("{0}|{1}|{2}|{3}|{4}", action, pageContext.Page.PageId, settings.ElementId, updatePostThreadId, updatePostPostId);
                break;

            case "thread":
                int? threadPage = GetInteger(pageContext.Parameters, "page");
                long threadId   = GetLong(pageContext.Parameters, "threadid").Value;
                content.PartialViewName = "ForumThread";
                content.ThreadViewModel = _forumPortalService.GetThreadViewModel(content.Page, tenantId, userId, settings.ElementId, threadId, threadPage);
                break;

            default:
                int?threadsPage = GetInteger(pageContext.Parameters, "page");
                content.ThreadsViewModel = _forumPortalService.GetThreadsViewModel(pageContext.Page, tenantId, userId, settings.ElementId, threadsPage);
                content.PartialViewName  = "Forum";
                break;
            }

            // Return forum content
            return(content);
        }