public async Task InsertTodoItemAsync (ToDoItem todoItem) { try { // This code inserts a new TodoItem into the database. When the operation completes // and Mobile Services has assigned an Id, the item is added to the CollectionView await todoTable.InsertAsync (todoItem); Items.Add (todoItem); } catch (MobileServiceInvalidOperationException e) { Console.Error.WriteLine (@"ERROR {0}", e.Message); } }
public async Task CompleteItemAsync (ToDoItem item) { try { // This code takes a freshly completed TodoItem and updates the database. When the MobileService // responds, the item is removed from the list item.Complete = true; await todoTable.UpdateAsync (item); Items.Remove (item); } catch (MobileServiceInvalidOperationException e) { Console.Error.WriteLine (@"ERROR {0}", e.Message); } }
async partial void OnAdd (NSObject sender) { if (string.IsNullOrWhiteSpace (itemText.Text)) return; var newItem = new ToDoItem { Text = itemText.Text, Complete = false }; await todoService.InsertTodoItemAsync (newItem); var index = todoService.Items.FindIndex (item => item.Id == newItem.Id); TableView.InsertRows (new [] { NSIndexPath.FromItemSection (index, 0) }, UITableViewRowAnimation.Top); itemText.Text = ""; }