예제 #1
0
        public async Task <ActionResult> Delete(int id = 0)
        {
            if (this.HttpContext.Session.IsAnonymousUser())
            {
                return(RedirectToAction("Index", "Home"));
            }

            var message = await MessageGuiHelper.GetMessageAsync(id);

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

            var thread = await ThreadGuiHelper.GetThreadAsync(message.ThreadID);

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

            // Only delete if the message isn't the first in the thread (as that's not allowed), and whether the user is allowed to delete messages in that forum at all.
            var messageIsFirstInThread = await ThreadGuiHelper.CheckIfMessageIsFirstInThreadAsync(thread.ThreadID, id);

            if (!messageIsFirstInThread && this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.EditDeleteOtherUsersMessages))
            {
                await MessageManager.DeleteMessageAsync(id, thread.ThreadID);
            }

            return(RedirectToAction("Index", "Thread", new { threadId = thread.ThreadID, pageNo = 1 }));
        }