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);
            }
        }
        private async Task<int> ShowConflictDialog(ToDoItem localItem, JObject serverValue)
        {
            var dialog = new UIAlertView("Conflict between local and server versions",
                    "How do you want to resolve this conflict?\n\n" + "Local item: \n" + localItem +
                    "\n\nServer item:\n" + serverValue.ToObject<ToDoItem>(), null, "Cancel", LOCAL_VERSION, SERVER_VERSION);

            var clickTask = new TaskCompletionSource<int>();
            dialog.Clicked += (sender, e) =>
            {
                clickTask.SetResult(e.ButtonIndex);
            };

            dialog.Show();

            return await clickTask.Task;
        }
        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 = "";
        }