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); } }
public async Task<int> InsertTodoItemAsync(TodoItem todoItem) { try { // TODO:: Uncomment this line out to use Mobile Services await todoTable.InsertAsync(todoItem); Items.Add(todoItem); return Items.IndexOf(todoItem); } catch (Exception e) // TODO:: Optional - catch MobileServiceInvalidOperationException instead of generic Exception { Console.Error.WriteLine(@"ERROR {0}", e.Message); return 0; } }
public async Task<int> 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); return Items.IndexOf(todoItem); } catch (MobileServiceInvalidOperationException e) { // In a previous version of Azure Mobile Services this exception was wrapped // in an Exception. This is why I've duplicated the code for handling it, // but probably for newer versions of Azure Mobile services you could // have simpler exception handling. Console.Error.WriteLine(@"ERROR {0}", e.Message); UIAlertView alert = new UIAlertView() { Title = "Error", Message = e.Message } ; alert.AddButton("Ok"); alert.Show(); return -1; } catch (Exception ex) { var exDetail = (ex.InnerException.InnerException as MobileServiceInvalidOperationException); Console.WriteLine(exDetail.Message); UIAlertView alert = new UIAlertView() { Title = "Error", Message = exDetail.Message } ; alert.AddButton("Ok"); alert.Show(); return -1; } }
public async Task CompleteItemAsync(TodoItem item) { try { item.Complete = true; // This code takes a freshly completed TodoItem and updates the database. When the MobileService // responds, the item is removed from the list // TODO:: Uncomment this line to use Mobile Services await todoTable.UpdateAsync(item); Items.Remove(item); } catch (Exception e) // TODO:: Optional - catch MobileServiceInvalidOperationException instead of generic Exception { Console.Error.WriteLine (@"ERROR {0}", e.Message); } }
public async Task<int> 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); return Items.IndexOf(todoItem); } catch (MobileServiceInvalidOperationException e) { Console.Error.WriteLine(@"ERROR {0}", e.Message); return 0; } }
public async void AddItem(View view) { if (client == null || string.IsNullOrWhiteSpace(textNewTodo.Text)) { return; } // Create a new item var item = new TodoItem() { Text = textNewTodo.Text, Complete = false }; try { // Insert the new item await todoTable.InsertAsync(item); if (!item.Complete) { adapter.Add(item); } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } textNewTodo.Text = ""; }
public async Task CheckItem(TodoItem item) { if (client == null) return; // Set the item as completed and update it in the table item.Complete = true; try { await todoTable.UpdateAsync(item); if (item.Complete) adapter.Remove(item); } catch (Exception e) { CreateAndShowDialog(e, "Error"); } }
public async void AddItem(View view) { // Create a new item var item = new TodoItem() { Text = textNewTodo.Text, Complete = false }; // TODO:: Uncomment the following code when using a mobile service try { // Insert the new item await todoTable.InsertAsync(item); if (!item.Complete) adapter.Add(item); } catch (Exception e) { CreateAndShowDialog(e, "Error"); } // TODO:: Comment out these lines to remove the in-memory list todoItemList.Add(item); adapter.Add(item); // NOTE:: End of lines to comment out textNewTodo.Text = ""; }
public async Task CheckItem(TodoItem item) { // Set the item as completed and update it in the table item.Complete = true; // TODO:: Uncomment the following code when using a mobile service try { await todoTable.UpdateAsync(item); if (item.Complete) adapter.Remove(item); } catch (Exception e) { CreateAndShowDialog(e, "Error"); } // TODO:: Comment out these lines to remove the in-memory list todoItemList.Add(item); if (item.Complete) adapter.Remove(item); // NOTE:: End of lines to comment out }
async partial void OnAdd(NSObject sender) { if (string.IsNullOrWhiteSpace(itemText.Text)) return; var newItem = new TodoItem() { Text = itemText.Text, Complete = false }; int index = await todoService.InsertTodoItemAsync(newItem); TableView.InsertRows(new [] { NSIndexPath.FromItemSection(index, 0) }, UITableViewRowAnimation.Top); itemText.Text = ""; }
public TodoItemWrapper(TodoItem item) { this.TodoItem = item; }
async partial void OnAdd(NSObject sender) { if (string.IsNullOrWhiteSpace(itemText.Text)) return; string deviceToken = ((AppDelegate)UIApplication.SharedApplication.Delegate).DeviceToken; var newItem = new TodoItem() { Text = itemText.Text, Complete = false, DeviceToken = deviceToken }; int index = await todoService.InsertTodoItemAsync(newItem); TableView.InsertRows(new [] { NSIndexPath.FromRowSection(index, 0) }, UITableViewRowAnimation.Top); itemText.Text = ""; }
public async void AddItem(View view) { if (client == null || string.IsNullOrWhiteSpace(textNewTodo.Text)) { return; } // Create a new item var item = new TodoItem() { Text = textNewTodo.Text, Complete = false }; try { // Insert the new item await todoTable.InsertAsync(item); if (!item.Complete) { adapter.Add(item); } } /* TODO:: NOTE:: does not match WP8 example exactly, use exception handling below */ catch (MobileServiceInvalidOperationException e) { CreateAndShowDialog(e.Response.Content.ToString(), "Error"); } catch (Exception ex) { var exDetail = (ex.InnerException.InnerException as MobileServiceInvalidOperationException); CreateAndShowDialog(exDetail, "Error"); } textNewTodo.Text = ""; }