Exemplo n.º 1
0
        public async Task <ActionResult> Add(int threadId = 0, int messageIdToQuote = 0)
        {
            if (this.HttpContext.Session.IsAnonymousUser())
            {
                return(RedirectToAction("Index", "Home"));
            }

            var(userMayAddMessages, thread) = await PerformAddMessageSecurityChecksAsync(threadId);

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

            MessageEntity messageToQuote       = null;
            UserEntity    userOfMessageToQuote = null;

            if (messageIdToQuote > 0)
            {
                messageToQuote = await MessageGuiHelper.GetMessageAsync(messageIdToQuote);

                if (messageToQuote == null || messageToQuote.ThreadID != threadId)
                {
                    // doesn't exist, or is in another thread, ignore.
                    return(RedirectToAction("Index", "Home"));
                }

                userOfMessageToQuote = await UserGuiHelper.GetUserAsync(messageToQuote.PostedByUserID);

                if (userOfMessageToQuote == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            var forum = await _cache.GetForumAsync(thread.ForumID);

            if (forum == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            string messageTextForEditor = messageToQuote == null
                                ? string.Empty
                                : string.Format("@quote {0}{1}{2}{1}@end{1}", userOfMessageToQuote.NickName, Environment.NewLine,
                                                messageToQuote.MessageText);
            var messageData = new MessageData()
            {
                MessageText         = messageTextForEditor,
                CurrentUserID       = this.HttpContext.Session.GetUserID(),
                ForumID             = forum.ForumID,
                ThreadID            = thread.ThreadID,
                ForumName           = forum.ForumName,
                SectionName         = await _cache.GetSectionNameAsync(forum.SectionID),
                ThreadSubject       = thread.Subject,
                PageNo              = 1,
                LastMessageInThread = await ThreadGuiHelper.GetLastMessageInThreadDtoAsync(threadId),
            };

            return(View(messageData));
        }