Esempio n. 1
0
 public int AddItem(TodoItem item)
 {
     item.TodoListId = this.TodoListId;
       item.TodoList = this;
       _todoItems.Add(item);
       return item.TodoItemId;
 }
Esempio n. 2
0
 private Int32 FindIndex(TodoItem item)
 {
     var ix = _todoItems.FindIndex(s => s.TodoItemId == item.TodoItemId);
       if (ix == -1) {
     throw new Exception("Unable to locate TodoItem: " + item.TodoItemId);
       }
       return ix;
 }
Esempio n. 3
0
 private int FindIndex(TodoItem item)
 {
     var ix = _todoItems.FindIndex(s => s.TodoItemId == item.TodoItemId);
     if (ix == -1)
     {
         throw new Exception("Can't find TodoItem: " + item.TodoItemId);
     }
     return ix;
 }
 private bool BeforeSaveTodoItem(TodoItem todoItem, EntityInfo info)
 {
     var todoList = Context.TodoLists.FirstOrDefault(tl => tl.TodoListId == todoItem.TodoListId);
     return (null != todoList) || throwCannotFindParentTodoList();
 }
Esempio n. 5
0
 public void ReplaceItem(TodoItem item)
 {
     var ix = FindIndex(item);
       item.TodoList = this;
       _todoItems[ix] = item;
 }
Esempio n. 6
0
 public void RemoveItem(TodoItem item)
 {
     var ix = FindIndex(item);
       _todoItems.RemoveAt(ix);
       item.TodoList = null;
 }
        public void PopulateWithSampleData()
        {
            var newList = new TodoList { Title = "Before work"};

            AddTodoList(newList);
            var listId = newList.TodoListId;
            var newItem = new TodoItem { TodoListId = listId, Title = "Make coffee", IsDone = false };
            AddTodoItem(newItem);
            newItem = new TodoItem { TodoListId = listId, Title = "Turn heater off", IsDone = false };
            AddTodoItem(newItem);
        }
 public void ValidateTodoItem(TodoItem todoItem)
 {
     var errs = todoItem.Validate();
     if (errs.Length <= 0) return;
     var msg =
         string.Format("TodoItem {0} '{1}' failed validation: {2}",
                       todoItem.TodoItemId, todoItem.Title, errs);
     throw new ValidationError(msg);
 }
 private void DeleteTodoItem(TodoItem item)
 {
     var todoList = FindTodoList(item.TodoListId, true);
     // if we delete a list ; by the time we get to the items the list is no longer there.
     if (todoList != null)
     {
         todoList.RemoveItem(item);
     }
 }
Esempio n. 10
0
 private void ModifyTodoItem(TodoItem item)
 {
     ValidateTodoItem(item);
     var todoList = FindTodoList(item.TodoListId);
     todoList.ReplaceItem(item);
 }
Esempio n. 11
0
        private void AddTodoItem(TodoItem item)
        {
            if (item.TodoItemId <= 0)
            {
                item.TodoItemId = AddMapping(typeof(TodoItem), item.TodoItemId);
            }
            if (item.TodoListId < 0)
            {
                item.TodoListId = FindRealId(typeof(TodoList), item.TodoListId);
            }

            ValidateTodoItem(item);
            var todoList = FindTodoList(item.TodoListId);
            todoList.AddItem(item);
        }
Esempio n. 12
0
 private bool BeforeSaveTodoItem(TodoItem todoItem, EntityInfo info)
 {
     var todoList = Context.TodoLists.FirstOrDefault( l => l.TodoListId == todoItem.TodoListId);
       return (null == todoList)
          ? throwCannotFindParentTodoList()
          : UserId == todoList.UserId || throwCannotSaveEntityForThisUser();
 }