예제 #1
0
        public async Task Handle(SaveFolderCommand command)
        {
            var model = command.Model;

            if (model.Id == Guid.Empty)
            {
                throw new InvalidOperationException($"Model '{model.Name}' has empty id");
            }

            var folder = await folderRepository.Get(model.Id);

            if (folder != null)
            {
                folder.ChangeName(model.Name);
                folder.ChangeColor(new Color(model.Color));

                await folderRepository.Update(folder);

                eventBus.Publish(new FolderUpdatedEvent(model));
            }
            else
            {
                folder = model.ToEntity();
                await folderRepository.Add(folder);

                eventBus.Publish(new FolderAddedEvent(model));
            }
        }