private void ExecuteUpdateItemCommand(ViewModels.TodoItemViewModel item) { try { TodoItemRepository.GetForToDoListId(TodoList.Id).UpdateItem(item.TodoItem.Id, item.TodoItem); } catch { } }
private void ExecuteRemoveCommand(Models.TodoItem param) { try { var index = this.Items.IndexOf(this.SelectedItem); // Delete from repo TodoItemRepository.GetForToDoListId(TodoList.Id).DeleteItem(this.SelectedItem.TodoItem.Id); this.Items.Remove(this.SelectedItem); this.SelectedItem = this.Items[index]; } catch { this.SelectedItem = null; } }
public TodoListViewModel(Models.TodoList list) { this.TodoList = list; var repo = TodoItemRepository.GetForToDoListId(list.Id); var todoItems = repo.GetAllItems(); foreach (var item in todoItems) { this.Items.Add(new ViewModels.TodoItemViewModel(item)); } }
private void ExecuteAddCommand(string title) { try { var index = this.Items.IndexOf(this.SelectedItem); var item = new TodoItemViewModel(TodoItemRepository.GetDefault().Factory(title: title)); // Set the ListId item.TodoItem.ListId = TodoList.Id; // Add to repo TodoItemRepository.GetForToDoListId(TodoList.Id).InsertItem(item.TodoItem); // Insert into ViewModel collection this.Items.Insert((index > -1) ? index : 0, item); this.SelectedItem = item; } catch { this.SelectedItem = null; } }