public int AddItem(TodoItem item) { item.TodoListId = this.TodoListId; item.TodoList = this; _todoItems.Add(item); return item.TodoItemId; }
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; }
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(); }
public void ReplaceItem(TodoItem item) { var ix = FindIndex(item); item.TodoList = this; _todoItems[ix] = item; }
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); } }
private void ModifyTodoItem(TodoItem item) { ValidateTodoItem(item); var todoList = FindTodoList(item.TodoListId); todoList.ReplaceItem(item); }
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); }
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(); }