Beispiel #1
0
        private Form GetUpdateThreadForm(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
            ForumThread forumThread = _forumService.GetThread(_authenticationService.TenantId, elementId, threadId);

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

            form.Fields.Add("subject", new TextField
            {
                Name                  = "subject",
                Label                 = ElementResource.ForumSubjectLabel,
                MaxLength             = ForumLengths.SubjectMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ForumSubjectMaxLengthMessage, "subject", ForumLengths.SubjectMaxLength),
                Required              = true,
                RequiredErrorMessage  = ElementResource.ForumSubjectRequiredMessage,
                Value                 = forumThread.Subject
            });
            form.Fields.Add("message", new MultiLineTextField
            {
                Name                 = "message",
                Label                = ElementResource.ForumMessageLabel,
                Required             = true,
                RequiredErrorMessage = ElementResource.ForumMessageRequiredMessage,
                Rows                 = 10,
                Value                = forumThread.Message
            });
            form.Fields.Add("notify", new BooleanField
            {
                Name  = "notify",
                Label = ElementResource.ForumNotifyLabel,
                Value = forumThread.Notify
            });
            form.SubmitLabel = ElementResource.ForumUpdateThreadButtonLabel;

            // Return result
            return(form);
        }
Beispiel #2
0
        private string GetPostUrl(Page page, bool authenticated, ForumAction action, ForumThread thread, ForumPost post)
        {
            string     url       = null;
            IUrlHelper urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);

            switch (action)
            {
            case ForumAction.ReplyPost:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "replypost", threadid = thread.ThreadId, postid = post.PostId });
                break;

            case ForumAction.QuotePost:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "quotepost", threadid = thread.ThreadId, postid = post.PostId });
                break;

            case ForumAction.UpdatePost:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "updatepost", threadid = thread.ThreadId, postid = post.PostId });
                break;
            }
            return(GetAuthenticatedUrl(urlHelper, url, authenticated));
        }
Beispiel #3
0
        private FormResult PostUpdatePostForm(Form form)
        {
            // Get logged on user details
            long tenantId = _authenticationService.TenantId;
            long userId   = _authenticationService.GetCurrentUser().User.UserId;

            // Get page, element and thread identifiers
            string[] parts     = form.Context.Split('|');
            long     pageId    = Convert.ToInt64(parts[1]);
            long     elementId = Convert.ToInt64(parts[2]);
            long     threadId  = Convert.ToInt64(parts[3]);
            long     postId    = Convert.ToInt64(parts[4]);

            // Get existing thread details
            ForumThread forumThread = _forumService.GetThread(tenantId, elementId, threadId);

            // Get information required to update post
            UpdatePostInfo info = new UpdatePostInfo
            {
                ElementId = elementId,
                Message   = ((MultiLineTextField)form.Fields["message"]).Value,
                PostId    = postId,
                TenantId  = tenantId,
                ThreadId  = threadId,
                UserId    = userId
            };

            // Update post
            _forumService.UpdatePost(info);

            // Get thread page that new post is on
            int page = _forumService.GetThreadPage(tenantId, info.ElementId, info.ThreadId, postId);

            // Return form result with no errors
            string status = _forumUrlService.GetThreadUrl(pageId, threadId, forumThread.Subject, page);

            return(_formHelperService.GetFormResult(status));
        }
Beispiel #4
0
        private string GetThreadUrl(Page page, bool authenticated, ForumAction action, ForumThread thread)
        {
            string     url       = null;
            IUrlHelper urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);

            switch (action)
            {
            case ForumAction.ReplyThread:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "replythread", threadid = thread.ThreadId });
                break;

            case ForumAction.QuoteThread:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "quotethread", threadid = thread.ThreadId });
                break;

            case ForumAction.UpdateThread:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "updatethread", threadid = thread.ThreadId });
                break;

            case ForumAction.DeleteThread:
                url = urlHelper.PageUrl(page, thread.Subject, new { forumaction = "deletethread", threadid = thread.ThreadId });
                break;
            }
            return(GetAuthenticatedUrl(urlHelper, url, authenticated));
        }
        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);
        }