private void submitButton_Click(object sender, EventArgs e)
        {
            string name = "";
            string description = "";
            int priority;
            int index;

            if (nameTextBox.Text != "")
            {
                name = nameTextBox.Text;
            }
            if (descriptionTextBox.Text != "")
            {
                description = descriptionTextBox.Text;
            }
            if (!Int32.TryParse(priorityTextBox.Text, out priority))
            {
                MessageBox.Show("Input is not valid for priority, should be a number");
                return;
            }
            if (!Int32.TryParse(indexTextBox.Text, out index))
            {
                MessageBox.Show("Input is not valid for index, should be a number");
                return;
            }
            if (state.getTakenIndices().Contains(index))
            {
                MessageBox.Show("Index already taken, try another");
                return;
            }
            else
            {
                this.createdItem = new TodoItemCreated(Guid.NewGuid(), name, description, priority, index);
            }
            this.Close();
        }
 private TodoItemCreated getRandomTodoItemCreated()
 {
     Guid newGuid = Guid.NewGuid();
     TodoItemCreated todoItemCreated = new TodoItemCreated(newGuid, getRandomString(nameLength), getRandomString(descriptionLenght), getNextPriority(), getFirstAvailableIndex());
     return todoItemCreated;
 }
        public IEvent transformEvent(TodoItemCreated toTransform, IEvent transformAgainst)
        {
            if (transformAgainst.GetType().Equals(typeof(TodoItemCreated)))
            {
                TodoItemCreated transFormAgainstCreated = (TodoItemCreated)transformAgainst;
                if (transFormAgainstCreated.aggregateId == toTransform.aggregateId)
                {
                    if (transFormAgainstCreated.Equals(toTransform))
                    {
                        //Both events are the same so remove one.
                        return new Unused();
                    }
                    //Else cannot create same id item so conflict.
                    return null;
                }
            }
            else if (transformAgainst.GetType().Equals(typeof(TodoItemDeleted)))
            {
                //Create after delete is no problem.
            }
            else if (transformAgainst.GetType().Equals(typeof(TodoItemIndexChanged)))
            {
                TodoItemIndexChanged transFormAgainstIndex = (TodoItemIndexChanged)transformAgainst;
                if (transFormAgainstIndex.newIndex == toTransform.index)
                {
                    // Create new transform at index +1. This is because the client side has lower prio than server side events.
                    toTransform = new TodoItemCreated(toTransform.aggregateId, toTransform.name, toTransform.description, toTransform.priority, toTransform.index + 1);
                }
            }

            return toTransform;
        }