示例#1
0
        public static TodoListState Write(object command, TodoListState todoList)
        {
            switch (command)
            {
            case NameTodoList c:
                todoList = Transition(todoList, new TodoListNamed(c.AggregateId, c.Name));
                break;

            case AddTodoItem c:
                if (todoList.Items.ContainsKey(c.ItemNumber))
                {
                    throw new ArgumentException("This list already has an item with that number");
                }
                todoList = Transition(todoList, new TodoItemAdded(c.AggregateId, c.ItemText, c.ItemNumber));
                break;

            case CheckTodoItem c:
                todoList = Transition(todoList, new TodoItemChecked(c.AggregateId, c.ItemNumber));
                break;

            case UncheckTodoItem c:
                todoList = Transition(todoList, new TodoItemUnchecked(c.AggregateId, c.ItemNumber));
                break;
            }

            return(todoList);
        }
示例#2
0
 private static TodoListState Transition(TodoListState todoList, object @event)
 {
     todoList.Emit(@event);
     return(todoList);
 }