Beispiel #1
0
        public ActionResult DeleteTopic(int id)
        {
            var topicModelFromRepo = _repository.GetTopicById(id);

            if (topicModelFromRepo == null)
            {
                return(NotFound());
            }
            _repository.DeleteTopic(topicModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
Beispiel #2
0
 public void DeleteTopic(Topic topic, User user)
 {
     if (user.IsInRole(PermanentRoles.Moderator) || user.UserID == topic.StartedByUserID)
     {
         _moderationLogService.LogTopic(user, ModerationType.TopicDelete, topic, null);
         _topicRepository.DeleteTopic(topic.TopicID);
         RecalculateReplyCount(topic);
         var forum = _forumService.Get(topic.ForumID);
         _forumService.UpdateCounts(forum);
         _forumService.UpdateLast(forum);
     }
     else
     {
         throw new InvalidOperationException("User must be Moderator or topic starter to delete topic.");
     }
 }
Beispiel #3
0
        public async Task <IActionResult> DeleteTopic(int id)
        {
            var topic = await _repository.Get(id);

            if (topic == null)
            {
                return(NotFound());
            }

            var ar = await _authorizationService.AuthorizeAsync(HttpContext.User, topic, "Permission");

            if (!ar.Succeeded)
            {
                return(Forbid());
            }

            _repository.DeleteTopic(id);
            await _repository.SaveChangesAsync();

            return(NoContent());
        }
        public async Task DeleteTopic(Topic topic, User user)
        {
            if (user.IsInRole(PermanentRoles.Moderator) || user.UserID == topic.StartedByUserID)
            {
                await _moderationLogService.LogTopic(user, ModerationType.TopicDelete, topic, null);

                await _topicRepository.DeleteTopic(topic.TopicID);

                await _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = topic.TopicID, IsForRemoval = true });
                await RecalculateReplyCount(topic);

                var forum = await _forumService.Get(topic.ForumID);

                _forumService.UpdateCounts(forum);
                await _forumService.UpdateLast(forum);
            }
            else
            {
                throw new InvalidOperationException("User must be Moderator or topic starter to delete topic.");
            }
        }
Beispiel #5
0
        public void Invoke(string[] args)
        {
            bool  showHelp          = false;
            bool  replyToTopic      = false;
            bool  refresh           = false;
            bool  edit              = false;
            bool  delete            = false;
            bool  report            = false;
            bool  modReply          = false;
            bool? lockTopic         = null;
            bool? stickyTopic       = null;
            bool? globalStickyTopic = null;
            long? replyId           = null;
            short?moveToBoard       = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "r|reply",
                "Reply to the topic.",
                x => replyToTopic = x != null
                );
            options.Add(
                "R|refresh",
                "Refresh the current topic.",
                x => refresh = x != null
                );
            options.Add(
                "e|edit:",
                "Edits the topic or a reply if a {ReplyID} is specified.",
                x =>
            {
                edit = true;
                if (x.IsLong())
                {
                    replyId = x.ToLong();
                }
            }
                );
            options.Add(
                "d|delete:",
                "Deletes the topic or a reply if a {ReplyID} is specified.",
                x =>
            {
                delete = true;
                if (x.IsLong())
                {
                    replyId = x.ToLong();
                }
            }
                );
            options.Add(
                "report:",
                "Report abuse for the topic or a reply if a {ReplyID} is specified.",
                x =>
            {
                report = true;
                if (x.IsLong())
                {
                    replyId = x.ToLong();
                }
            }
                );

            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "mr|modReply",
                    "A reply only moderators can see.",
                    x =>
                {
                    modReply     = x != null;
                    replyToTopic = x != null;
                }
                    );
                options.Add(
                    "l|lock",
                    "Locks the topic preventing further replies except modreplies.",
                    x => lockTopic = x != null
                    );
                options.Add(
                    "s|sticky",
                    "Sticky's the topic keeping it at the top of the board regardless of last reply date.",
                    x => stickyTopic = x != null
                    );
                options.Add(
                    "g|globalSticky",
                    "Sticky's the topic keeping it at the top of \"All Activity Board\".",
                    x => globalStickyTopic = x != null
                    );
                options.Add(
                    "m|move=",
                    "Moves the topic to the board with the specified {BoardID}.",
                    x => moveToBoard = x.ToShort()
                    );
            }

            try
            {
                if (args == null)
                {
                    this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                }
                else
                {
                    var parsedArgs = options.Parse(args).ToArray();
                    if (parsedArgs.Length == args.Length)
                    {
                        if (parsedArgs.Length == 1)
                        {
                            if (parsedArgs[0].IsLong())
                            {
                                var topicId     = parsedArgs[0].ToLong();
                                var page        = 1;
                                var topic       = _topicRepository.GetTopic(topicId);
                                var isAnonymous = _boardRepository.GetBoard(topic.BoardID).Anonymous;
                                if (topic != null)
                                {
                                    if (topic.ModsOnly)
                                    {
                                        if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                        {
                                            WriteTopic(topicId, page);
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("You do not have permission to view this topic.");
                                        }
                                    }
                                    else
                                    {
                                        WriteTopic(topicId, page);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                            }
                        }
                        else if (parsedArgs.Length == 2)
                        {
                            if (parsedArgs[0].IsInt())
                            {
                                var topicId = parsedArgs[0].ToLong();
                                if (parsedArgs[1].IsInt())
                                {
                                    var page        = parsedArgs[1].ToInt();
                                    var topic       = _topicRepository.GetTopic(topicId);
                                    var isAnonymous = _boardRepository.GetBoard(topic.BoardID).Anonymous;
                                    if (topic != null)
                                    {
                                        if (topic.ModsOnly)
                                        {
                                            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                WriteTopic(topicId, page);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You do not have permission to view this topic.");
                                            }
                                        }
                                        else
                                        {
                                            WriteTopic(topicId, page);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else if (PagingUtility.Shortcuts.Any(x => parsedArgs[1].Is(x)))
                                {
                                    var page = PagingUtility.TranslateShortcut(parsedArgs[1], this.CommandResult.CommandContext.CurrentPage);
                                    WriteTopic(topicId, page);
                                    if (parsedArgs[1].Is("last") || parsedArgs[1].Is("prev"))
                                    {
                                        this.CommandResult.ScrollToBottom = true;
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid page number.", parsedArgs[1]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                        }
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (replyToTopic)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var topicId = parsedArgs[0].ToLong();
                                    var topic   = _topicRepository.GetTopic(topicId);
                                    if (topic != null)
                                    {
                                        if (!topic.Locked || (!topic.IsModsOnly() && modReply && this.CommandResult.CurrentUser.IsModerator) || this.CommandResult.CurrentUser.IsAdministrator)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (this.CommandResult.CommandContext.PromptData == null)
                                                {
                                                    this.CommandResult.WriteLine("Type your reply.");
                                                    this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} REPLY", topicId));
                                                }
                                                else
                                                {
                                                    _replyRepository.AddReply(new Reply
                                                    {
                                                        Username   = this.CommandResult.CurrentUser.Username,
                                                        PostedDate = DateTime.UtcNow,
                                                        LastEdit   = DateTime.UtcNow,
                                                        TopicID    = topicId,
                                                        Body       = BBCodeUtility.SimplifyComplexTags(
                                                            this.CommandResult.CommandContext.PromptData[0],
                                                            _replyRepository,
                                                            this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                            ),
                                                        ModsOnly = modReply && !topic.IsModsOnly()
                                                    });
                                                    this.CommandResult.CommandContext.PromptData = null;
                                                    var TOPIC = this.AvailableCommands.SingleOrDefault(x => x.Name.Is("TOPIC"));
                                                    TOPIC.Invoke(new string[] { topicId.ToString(), "last" });
                                                    this.CommandResult.WriteLine("Reply successfully posted.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' is for moderators only.", topicId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a topic ID.");
                            }
                        }
                        else if (edit)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var topicId = parsedArgs[0].ToLong();
                                    if (replyId == null)
                                    {
                                        var topic = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (topic.Username.Is(this.CommandResult.CurrentUser.Username) ||
                                                    (this.CommandResult.CurrentUser.IsModerator && !topic.IsModsOnly() && !topic.User.IsModerator && !topic.User.IsAdministrator) ||
                                                    this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (this.CommandResult.CommandContext.PromptData == null)
                                                    {
                                                        this.CommandResult.WriteLine("Edit the topic title.");
                                                        this.CommandResult.EditText = topic.Title;
                                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} EDIT Title", topicId));
                                                    }
                                                    else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                    {
                                                        this.CommandResult.WriteLine("Edit the topic body.");
                                                        this.CommandResult.EditText = topic.Body;
                                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} EDIT Body", topicId));
                                                    }
                                                    else if (this.CommandResult.CommandContext.PromptData.Length == 2)
                                                    {
                                                        topic.Title = this.CommandResult.CommandContext.PromptData[0];
                                                        topic.Body  = BBCodeUtility.SimplifyComplexTags(
                                                            this.CommandResult.CommandContext.PromptData[1],
                                                            _replyRepository,
                                                            this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                            );
                                                        topic.LastEdit = DateTime.UtcNow;
                                                        topic.EditedBy = this.CommandResult.CurrentUser.Username;
                                                        _topicRepository.UpdateTopic(topic);
                                                        this.CommandResult.CommandContext.PromptData = null;
                                                        this.CommandResult.WriteLine("Topic '{0}' was edited successfully.", topicId);
                                                        this.CommandResult.CommandContext.Restore();
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Topic '{0}' belongs to '{1}'. You are not authorized to edit it.", topicId, topic.Username);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        var reply = _replyRepository.GetReply((long)replyId);
                                        if (reply != null)
                                        {
                                            if (reply.TopicID == topicId)
                                            {
                                                if (!reply.Topic.Locked || (reply.ModsOnly && !reply.Topic.IsModsOnly()) || this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (reply.Username.Is(this.CommandResult.CurrentUser.Username) ||
                                                        (this.CommandResult.CurrentUser.IsModerator && !reply.IsModsOnly() && !reply.User.IsModerator && !reply.User.IsAdministrator) ||
                                                        this.CommandResult.CurrentUser.IsAdministrator)
                                                    {
                                                        if (this.CommandResult.CommandContext.PromptData == null)
                                                        {
                                                            this.CommandResult.WriteLine("Edit the reply body.");
                                                            this.CommandResult.EditText = reply.Body;
                                                            this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} EDIT Reply {1}", topicId, replyId));
                                                        }
                                                        else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                        {
                                                            reply.Body = BBCodeUtility.SimplifyComplexTags(
                                                                this.CommandResult.CommandContext.PromptData[0],
                                                                _replyRepository,
                                                                this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                                );
                                                            reply.LastEdit = DateTime.UtcNow;
                                                            reply.EditedBy = this.CommandResult.CurrentUser.Username;
                                                            _replyRepository.UpdateReply(reply);
                                                            this.CommandResult.CommandContext.PromptData = null;
                                                            this.CommandResult.WriteLine("Reply '{0}' was edited successfully.", replyId);
                                                            this.CommandResult.CommandContext.Restore();
                                                        }
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("Reply '{0}' belongs to '{1}'. You are not authorized to edit it.", replyId, reply.Username);
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' does not contain a reply with ID '{1}'.", topicId, replyId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Reply '{0}' does not exist.", replyId);
                                        }
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a topic ID.");
                            }
                        }
                        else if (delete)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var topicId = parsedArgs[0].ToLong();
                                    if (replyId == null)
                                    {
                                        var topic = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (this.CommandResult.CommandContext.PromptData == null)
                                                    {
                                                        this.CommandResult.WriteLine("Are you sure you want to delete the topic titled \"{0}\"? (Y/N)", topic.Title);
                                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} DELETE CONFIRM", topicId));
                                                    }
                                                    else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                    {
                                                        if (this.CommandResult.CommandContext.PromptData[0].Is("Y"))
                                                        {
                                                            _topicRepository.DeleteTopic(topic);
                                                            this.CommandResult.WriteLine("Topic '{0}' was deleted successfully.", topicId);
                                                            this.CommandResult.CommandContext.PromptData = null;
                                                            if (this.CommandResult.CommandContext.PreviousContext != null &&
                                                                this.CommandResult.CommandContext.PreviousContext.Command.Is("TOPIC") &&
                                                                this.CommandResult.CommandContext.PreviousContext.Args.Contains(topicId.ToString()) &&
                                                                this.CommandResult.CommandContext.PreviousContext.Status == ContextStatus.Passive)
                                                            {
                                                                this.CommandResult.ClearScreen = true;
                                                                this.CommandResult.CommandContext.Deactivate();
                                                            }
                                                            else
                                                            {
                                                                this.CommandResult.CommandContext.Restore();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            this.CommandResult.WriteLine("Topic '{0}' was not deleted.", topicId);
                                                            this.CommandResult.CommandContext.PromptData = null;
                                                            this.CommandResult.CommandContext.Restore();
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("You are not an administrator. You are not authorized to delete topics.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID {0}.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        var reply = _replyRepository.GetReply((long)replyId);
                                        if (reply != null)
                                        {
                                            if (reply.TopicID == topicId)
                                            {
                                                if (!reply.Topic.Locked || (reply.ModsOnly && !reply.Topic.IsModsOnly()) || this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (reply.Username.Is(this.CommandResult.CurrentUser.Username) ||
                                                        (this.CommandResult.CurrentUser.IsModerator && !reply.IsModsOnly() && !reply.User.IsModerator && !reply.User.IsAdministrator) ||
                                                        this.CommandResult.CurrentUser.IsAdministrator)
                                                    {
                                                        _replyRepository.DeleteReply(reply);
                                                        this.CommandResult.WriteLine("Reply '{0}' was deleted successfully.", replyId);
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("Reply '{0}' belongs to '{1}'. You are not authorized to delete it.", replyId, reply.Username);
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' does not contain a reply with ID '{1}'.", topicId, replyId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Reply '{0}' does not exist.", replyId);
                                        }
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a topic ID.");
                            }
                        }
                        else if (report)
                        {
                            // allow user to report abuse.
                        }
                        else
                        {
                            if (lockTopic != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if ((bool)lockTopic || (!(bool)lockTopic && this.CommandResult.CurrentUser.IsAdministrator))
                                                {
                                                    topic.Locked = (bool)lockTopic;
                                                    _topicRepository.UpdateTopic(topic);
                                                    string status = (bool)lockTopic ? "locked" : "unlocked";
                                                    this.CommandResult.WriteLine("Topic '{0}' was successfully {1}.", topicId, status);
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Only administrators can unlock topics.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You are not authorized to lock moderator topics.");
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID {0}.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                            if (stickyTopic != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                topic.Stickied = (bool)stickyTopic;
                                                _topicRepository.UpdateTopic(topic);
                                                string status = (bool)stickyTopic ? "stickied" : "unstickied";
                                                this.CommandResult.WriteLine("Topic '{0}' was successfully {1}.", topicId, status);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You are not authorized to sticky/unsticky moderator topics.");
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                            if (globalStickyTopic != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                topic.GlobalSticky = (bool)globalStickyTopic;
                                                _topicRepository.UpdateTopic(topic);
                                                string status = (bool)globalStickyTopic ? "stickied" : "unstickied";
                                                this.CommandResult.WriteLine("Topic '{0}' was successfully globally {1}.", topicId, status);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You are not authorized to globally sticky/unsticky moderator topics.");
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                            if (moveToBoard != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            var board = _boardRepository.GetBoard((short)moveToBoard);
                                            if (board != null)
                                            {
                                                if (!board.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                                    {
                                                        if (!board.ModsOnly || this.CommandResult.CurrentUser.IsAdministrator)
                                                        {
                                                            topic.BoardID = (short)moveToBoard;
                                                            _topicRepository.UpdateTopic(topic);
                                                            this.CommandResult.WriteLine("Topic '{0}' was successfully moved to board '{1}'.", topicId, moveToBoard);
                                                        }
                                                        else
                                                        {
                                                            this.CommandResult.WriteLine("You are not authorized to move topics onto moderator boards.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("You are not authorized to move moderator topics.");
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Board '{0}' is locked.", moveToBoard);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("There is no board with ID '{0}'.", moveToBoard);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a board ID.");
                                }
                            }
                            if (refresh)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        WriteTopic(topicId, this.CommandResult.CommandContext.CurrentPage);
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                        }
                    }
                }
            }
            catch (OptionException ex)
            {
                this.CommandResult.WriteLine(ex.Message);
            }
        }
Beispiel #6
0
 public async Task DeleteTopic(int id)
 {
     await _topicRepository.DeleteTopic(id);
 }
Beispiel #7
0
 public async Task <bool> DeleteTopic(string topicName, string currentLoggedUser)
 {
     return(await _topicRepository.DeleteTopic(topicName, currentLoggedUser));
 }
Beispiel #8
0
 public bool DeleteTopic(System.Int32 TopicId)
 {
     return(_iTopicRepository.DeleteTopic(TopicId));
 }
 public void DeleteTopic(Topic topic)
 {
     _topicRepository.DeleteTopic(topic);
 }