/** * Updates an existing note item in azure */ public async Task UpdateNoteAsync(NotesItem notesItem) { for (int i = 0; i < Items.Count; i++) { if ((Items[i].Id).Equals(notesItem.Id)) { Items[i].Text = notesItem.Text; } } await notesTable.UpdateAsync(notesItem); }
/** * Inserts a new note item into azure */ public async Task InsertTodoItemAsync(NotesItem notesItem) { try { await notesTable.InsertAsync(notesItem); #if OFFLINE_SYNC_ENABLED await SyncAsync(); // Send changes to the mobile app backend. #endif Items.Add(notesItem); } catch (MobileServiceInvalidOperationException e) { Console.Error.WriteLine(@"ERROR {0}", e.Message); } }
/** * Deleting an existing note item in azure */ public async Task CompleteItemAsync(NotesItem item) { try { item.Delete = true; await notesTable.UpdateAsync(item); #if OFFLINE_SYNC_ENABLED await SyncAsync(); // Send changes to the mobile app backend. #endif Items.Remove(item); } catch (MobileServiceInvalidOperationException e) { Console.Error.WriteLine(@"ERROR {0}", e.Message); } }
/** * Actions that can occur after storyboard is loaded */ public override async void ViewDidLoad() { base.ViewDidLoad(); notesService = NotesService.DefaultService; await notesService.InitializeStoreAsync(); //actions by clicking done button doneNotesButton.TouchUpInside += async(object sender, EventArgs e) => { if (string.IsNullOrWhiteSpace(notesTextArea.Text)) { return; } if (!isInEditingMode) { // new note var newItem = new NotesItem { Text = notesTextArea.Text, Delete = false }; await notesService.InsertTodoItemAsync(newItem); } else { // note already exists and has to be updated in azure note.Text = notesTextArea.Text; await notesService.UpdateNoteAsync(note); isInEditingMode = false; } notesTextArea.Text = ""; await notesService.RefreshDataAsync(); }; }