public override void Execute(MoveTopicCommand command)
        {
            // Nothing special to do here, permissions have been checked and parameters validated!
            ITopicDto topic = this.topics.ReadById(command.TopicId);

            if (topic == null)
            {
                // TODO:
                throw new ArgumentNullException("TopicId");
            }
            IForumDto forum = this.forums.ReadById(command.DestinationForumId);

            if (forum == null)
            {
                // TODO:
                throw new ArgumentNullException("ForumId");
            }
            // Moving to another forum?
            if (topic.Forum.Id != forum.Id)
            {
                // Create a new topic or move the old one?
                if (command.CreateMovedTopic)
                {
                    CreateTopicCommand ctc = new CreateTopicCommand {
                        Content = topic.Content,
                        ForumId = forum.Id,
                        State   = topic.State,
                        Subject = topic.Subject,
                        Type    = topic.Type
                    };
                    this.commandDispatcher.Dispatch <CreateTopicCommand>(ctc);

                    // TODO:
                    String newTopicId = this.taskDatastore.GetTaskStatus(ctc.TaskId).Item1;

                    this.commandDispatcher.Dispatch <MergeTopicsCommand>(new MergeTopicsCommand {
                        CreateReplyForTopics = false,
                        SourceTopicIds       = new String[] { topic.Id },
                        DestinationTopicId   = newTopicId
                    });

                    // TODO: Change Type on original topic !!!!!
                }
                else
                {
                    this.topics.Move(topic.Id, forum.Id);
                }
            }

            this.SetTaskStatus(command.TaskId, command.TopicId, "Topic");
        }
        public override void Execute(MergeTopicsCommand command)
        {
            // Nothing special to do here, permissions have been checked and parameters validated!
            ITopicDto rootTopic = this.topics.ReadById(command.DestinationTopicId);

            if (rootTopic == null)
            {
                // TODO:
                throw new ArgumentNullException("DestionationTopicId");
            }

            List <ITopicDto> sources = new List <ITopicDto>();

            command.SourceTopicIds.Distinct().ToList().ForEach((t) => {
                ITopicDto topic = this.topics.ReadById(t);
                if (topic == null)
                {
                    // TODO:
                    throw new ArgumentException($"Could not locate a topic with id {t}");
                }
                sources.Add(topic);
            });

            if (command.CreateReplyForTopics)
            {
                sources.ForEach((s) => {
                    this.commandDispatcher.Dispatch <CreateReplyCommand>(new CreateReplyCommand {
                        Content = s.Content,
                        // TODO:
                        State   = ReplyState.None,
                        Subject = s.Subject,
                        TopicId = rootTopic.Id
                    });
                });
            }

            this.replies.MergeTopics(rootTopic.Id, sources.Select(s => s.Id));

            command.SourceTopicIds.ToList().ForEach((topicId) => {
                this.SetTaskStatus(command.TaskId, topicId, "Topic");
            });

            sources.ForEach((s) => {
                this.commandDispatcher.Dispatch <DeleteTopicCommand>(new DeleteTopicCommand {
                    Id = s.Id
                });
            });
        }
        public override void Execute(CreateTopicCommand command)
        {
            // Nothing special to do here, permissions have been checked and parameters validated!
            IForumDto forum = this.forums.ReadById(command.ForumId);

            if (forum == null)
            {
                // TODO:
                throw new ArgumentException("Parent forum not found!");
            }

            Topic     t        = new Topic(new Forum(forum), command.Subject, command.Content, command.Type, command.State);
            ITopicDto newTopic = this.topics.Create(t);

            this.SetTaskStatus(command.TaskId, newTopic.Id, "Topic");
        }
        public override void Execute(CreateReplyCommand command)
        {
            // Nothing special to do here, permissions have been checked and parameters validated!
            ITopicDto topic = null;
            IReplyDto reply = null;

            if (!String.IsNullOrWhiteSpace(command.ParentReplyId))
            {
                reply = this.replies.ReadById(command.ParentReplyId);
                if (reply == null)
                {
                    // TODO:
                    throw new ArgumentException("Parent reply not found!");
                }
                topic = this.topics.ReadById(reply.Topic.Id);
            }
            else
            {
                topic = this.topics.ReadById(command.TopicId);
            }
            if (topic == null)
            {
                // TODO:
                throw new ArgumentException("Parent topic not found!");
            }

            Reply r = null;

            if (reply != null)
            {
                r = new Reply(new Reply(reply), command.Subject, command.Content, command.State);
            }
            else
            {
                r = new Reply(new Topic(topic), command.Subject, command.Content, command.State);
            }
            this.replies.Create(r);

            this.SetTaskStatus(command.TaskId, r.Id, "Reply");
        }
Exemple #5
0
        public void UpdateTopic()
        {
            var parentCategory = Substitute.For <Domain.Category>("category", 1, "desc");

            parentCategory.Id.Returns("1");
            var parentForum = Substitute.For <Domain.Forum>(parentCategory, "forum", 1, "desc");

            parentForum.Id.Returns("1");

            Domain.Topic       oldTopic = new Domain.Topic(parentForum, "subject, topic2", "bla blalba", Domain.TopicType.Regular);
            UpdateTopicCommand command  = new UpdateTopicCommand {
                Id = "1", Subject = "a new subject", Content = "and new content"
            };
            ITopicDto dto = Substitute.For <ITopicDto>();

            var datastore = Substitute.For <ITopicDatastore>();

            datastore.Update(oldTopic).Returns <ITopicDto>(dto);

            var userProvider = Substitute.For <IUserProvider>();
            var user         = Substitute.For <IPrincipal>();
            var author       = Substitute.For <IAuthenticatedUser>();

            userProvider.Get(user).Returns <IAuthenticatedUser>(author);
            var taskDatastore = Substitute.For <ITaskDatastore>();

            UpdateTopicCommandHandler handler = new UpdateTopicCommandHandler(datastore, user, userProvider, taskDatastore);
            GenericValidationCommandHandlerDecorator <UpdateTopicCommand> val =
                new GenericValidationCommandHandlerDecorator <UpdateTopicCommand>(
                    handler,
                    new List <IValidator <UpdateTopicCommand> > {
                new UpdateTopicValidator(TestUtils.GetInt32IdValidator())
            }
                    );

            val.Execute(command);

            // Let's make sure the Update method on the datastore is actually called once. Nevermind the input argument.
            datastore.ReceivedWithAnyArgs(1).Update(oldTopic);
        }
Exemple #6
0
        public override void Execute(UpdateTopicCommand command)
        {
            // Permissions have been checked and parameters validated!
            ITopicDto dto = this.topics.ReadById(command.Id);

            if (dto == null)
            {
                throw new TopicNotFoundException(command.Id);
            }

            Topic t = new Topic(dto);

            t.SetEditor(this.userProvider.GetAuthor(this.user));
            t.SetSubject(command.Subject);
            t.SetContent(command.Content);
            t.ChangeType(command.Type);
            // TODO:
            //t.ClearAndAddProperties(command.Properties);

            this.topics.Update(t);

            this.SetTaskStatus(command.TaskId, command.Id, "Topic");
        }
Exemple #7
0
 public Topic(ITopicDto data) : base(data)
 {
     this.Forum   = data.Forum;
     this.ForumId = data.Forum.Id;
 }