Exemplo n.º 1
0
        public async Task <ActionResult> Add([Bind(nameof(NewThreadData.MessageText), nameof(NewThreadData.ThreadSubject), nameof(NewThreadData.IsSticky),
                                                   nameof(NewThreadData.Subscribe))]
                                             NewThreadData newThreadData, string submitButton, int forumId = 0)
        {
            if (submitButton != "Post")
            {
                // apparently canceled
                if (forumId <= 0)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(RedirectToAction("Index", "Forum", new { forumId = forumId }));
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var(userMayAddThread, forum, userMayAddStickThread) = await PerformAddThreadSecurityChecksAsync(forumId);

            if (!userMayAddThread)
            {
                return(RedirectToAction("Index", "Home"));
            }

            int newThreadId = 0;

            if (submitButton == "Post")
            {
                // allowed, proceed
                // parse message text to html
                var messageAsHtml = HnDGeneralUtils.TransformMarkdownToHtml(newThreadData.MessageText, ApplicationAdapter.GetEmojiFilenamesPerName(),
                                                                            ApplicationAdapter.GetSmileyMappings());
                var(newThreadIdFromCall, newMessageId) = await ForumManager.CreateNewThreadInForumAsync(forumId, this.HttpContext.Session.GetUserID(),
                                                                                                        newThreadData.ThreadSubject, newThreadData.MessageText,
                                                                                                        messageAsHtml, userMayAddStickThread&& newThreadData.IsSticky,
                                                                                                        this.Request.Host.Host, forum.DefaultSupportQueueID,
                                                                                                        newThreadData.Subscribe);

                newThreadId = newThreadIdFromCall;
                ApplicationAdapter.InvalidateCachedNumberOfThreadsInSupportQueues();
                if (this.HttpContext.Session.CheckIfNeedsAuditing(AuditActions.AuditNewThread))
                {
                    await SecurityManager.AuditNewThreadAsync(this.HttpContext.Session.GetUserID(), newThreadId);
                }

                _cache.Remove(CacheManager.ProduceCacheKey(CacheKeys.SingleForum, forumId));
            }

            return(Redirect(this.Url.Action("Index", "Thread", new { threadId = newThreadId, pageNo = 1 })));
        }