public ListAggregate(Guid id)
        {
            this.id = id;
            todoItems = new List<TodoItemAggregate>();

            Register<TodoItemCreated>(e =>
            {
                //If the list already contains the same item
                if (todoItems.Any(item => item.id == e.aggregateId))
                {
                    //Will never happen exept when same event gets handled twice... or when 2 random guids are the same.
                }
                else
                {
                    // Make sure index is unique.
                    freeIndexIfNeeded(e.index);
                    TodoItemAggregate newItem = new TodoItemAggregate(Guid.Empty);
                    newItem.RaiseEvent(e);
                    todoItems.Add(newItem);
                }
            });

            Register<TodoItemDeleted>(e =>
                {
                    if(!(todoItems.Any(item => item.id == e.aggregateId)))
                    {
                        // Item that needs to be deleted is not there.
                        Debug.WriteLine("Attempted to remove an item that was not there.");
                    }
                    else
                    {
                        todoItems.Remove(todoItems.First(item => item.id == e.aggregateId));
                    }

                });
            Register<TodoItemDescriptionChanged>(e => redirectToTodoItem(e));
            Register<TodoItemNameChanged>(e => redirectToTodoItem(e));
            Register<TodoItemPriorityChanged>(e => redirectToTodoItem(e));
            Register<TodoItemPriorityDecreased>(e => redirectToTodoItem(e));
            Register<TodoItemPriorityIncreased>(e => redirectToTodoItem(e));
            Register<TodoItemIndexChanged>(e =>
            {
                freeIndexIfNeeded(e.newIndex);
                redirectToTodoItem(e);
            });
            Register<TodoItemsDeleted>(e => removeMultiple(e));

            Register<ListCreated>(e =>
            {
                if (id.Equals(Guid.Empty))
                {
                    this.id = e.aggregateId;
                    this.name = e.name;
                }
            });

            Register<ListNameChanged>(e =>
            {
                this.name = e.newName;
            });
        }
        public void addTodoItem(ListState state, TodoItemAggregate todoItem)
        {
            this.state = state;
            this.todoItem = todoItem;
            // Set the correct positions.
            int adjustedYPos = offset + ((height + offset) * (todoItem.index-1));
            this.SetBounds(offset, adjustedYPos, width, height);

            this.BackColor = Color.White;

            nameLabel.Text = nameHeader;
            nameLabel.Font = standardFont;

            descriptionLabel.Text = descriptionHeader;
            descriptionLabel.Font = standardFont;

            priorityLabel.Text = priorityHeader;
            priorityLabel.Font = standardFont;

            indexLabel.Text = indexHeader;
            indexLabel.Font = standardFont;

            this.nameTextBox.Text= todoItem.name;
            this.descriptionTextBox.Text = todoItem.description;
            this.priorityTextBox.Text = todoItem.priority.ToString();
            this.indexTextBox.Text = todoItem.index.ToString();

            this.nameTextBox.Width = 190;
            this.nameTextBox.Font = standardFont;

            this.descriptionTextBox.Width = 190;
            this.descriptionTextBox.Font = standardFont;

            this.priorityTextBox.Width = 190;
            this.priorityTextBox.Font = standardFont;

            this.indexTextBox.Width = 190;
            this.indexTextBox.Font = standardFont;

            this.deleteButton.Text = "X";
            this.deleteButton.Width = 20;

            this.priorityUpButton.Text = "+";
            this.priorityUpButton.Width = 20;
            this.priorityUpButton.Height = 20;

            this.priorityDownButten.Text = "-";
            this.priorityDownButten.Width = 20;
            this.priorityDownButten.Height = 20;

            this.Controls.Add(nameLabel,0,0);
            this.Controls.Add(descriptionLabel,0,1);
            this.Controls.Add(priorityLabel, 0, 2);
            this.Controls.Add(nameTextBox,1,0);
            this.Controls.Add(descriptionTextBox,1,1);
            this.Controls.Add(priorityTextBox, 1, 2);
            this.Controls.Add(deleteButton, 2, 0);
            this.Controls.Add(priorityUpButton, 2, 2);
            this.Controls.Add(priorityDownButten, 3, 2);
            this.Controls.Add(indexLabel, 0, 3);
            this.Controls.Add(indexTextBox, 1, 3);

            nameTextBox.LostFocus += nameTextBox_LostFocus;
            nameTextBox.TextChanged += nameTextBox_TextChanged;
            descriptionTextBox.LostFocus += descriptionTextBox_LostFocus;
            descriptionTextBox.TextChanged += descriptionTextBox_TextChanged;
            priorityTextBox.TextChanged += priorityTextBox_TextChanged;
            priorityTextBox.LostFocus += priorityTextBox_LostFocus;
            indexTextBox.TextChanged += indexTextBox_TextChanged;
            indexTextBox.LostFocus += indexTextBox_LostFocus;

            deleteButton.Click += deleteButton_Click;
            priorityDownButten.Click += priorityDownButten_Click;
            priorityUpButton.Click += priorityUpButton_Click;
        }