public async void OnAdd(object sender, EventArgs e) { var todo = new TodoItem { Name = newItemName.Text }; await AddItem(todo); newItemName.Text = ""; newItemName.Unfocus(); }
public TodoItemImageViewModel(MobileServiceFile file, TodoItem todoItem, Action<TodoItemImageViewModel> deleteHandler) { this.deleteHandler = deleteHandler; this.uri = FileHelper.GetLocalFilePath(todoItem.Id, file.Name); this.name = file.Name; this.File = file; InitializeCommands(); }
public static async Task<TodoItemImageViewModel> CreateAsync(MobileServiceFile file, TodoItem todoItem, Action<TodoItemImageViewModel> deleteHandler) { var result = new TodoItemImageViewModel(); result.deleteHandler = deleteHandler; result.name = file.Name; result.File = file; result.uri = await FileHelper.GetLocalFilePathAsync(todoItem.Id, file.Name); result.InitializeCommands(); return result; }
public TodoItemViewModel(TodoItem todoItem, TodoItemManager itemManager) { if (todoItem == null) { throw new ArgumentNullException("todoItem"); } if (itemManager == null) { throw new ArgumentNullException("itemManager"); } this.todoItem = todoItem; this.itemManager = itemManager; InitializeImages(todoItem); InitializeCommands(); }
public static async Task<TodoItemViewModel> CreateAsync(TodoItem todoItem, TodoItemManager itemManager) { if (todoItem == null) { throw new ArgumentNullException("todoItem"); } if (itemManager == null) { throw new ArgumentNullException("itemManager"); } TodoItemViewModel result = new TodoItemViewModel(); result.todoItem = todoItem; result.itemManager = itemManager; await result.LoadImagesAsync(); result.InitializeCommands(); return result; }
public static async Task<TodoItemImageViewModel> CreateAsync(MobileServiceFile file, TodoItem todoItem, Action<TodoItemImageViewModel> deleteHandler) { var result = new TodoItemImageViewModel(); result.deleteHandler = deleteHandler; result.name = file.Name; result.File = file; var uri = await FileHelper.GetLocalFilePathAsync(todoItem.Id, file.Name); // hack until I figure out how to do this cross-platform if (Device.OS == TargetPlatform.Windows) { result.uri = new Uri(uri).AbsoluteUri; } else { result.uri = uri; } result.InitializeCommands(); return result; }
private async void InitializeImages(TodoItem todoItem) { IEnumerable<MobileServiceFile> files = await this.itemManager.GetImageFiles(todoItem); this.Images = new ObservableCollection<TodoItemImageViewModel>(files.Select(f => new TodoItemImageViewModel(f, this.todoItem, DeleteImage))); }
internal async Task<IEnumerable<MobileServiceFile>> GetImageFiles(TodoItem todoItem) { // FILES: Get files (local) return await this.todoTable.GetFilesAsync(todoItem); }
internal async Task DeleteImage(TodoItem todoItem, MobileServiceFile file) { // FILES: Deleting file await this.todoTable.DeleteFileAsync(file); // "Touch" the record to mark it as updated await this.todoTable.UpdateAsync(todoItem); }
internal async Task<MobileServiceFile> AddImage(TodoItem todoItem, string imagePath) { string targetPath = FileHelper.CopyTodoItemFile(todoItem.Id, imagePath); // FILES: Creating/Adding file MobileServiceFile file = await this.todoTable.AddFileAsync(todoItem, Path.GetFileName(targetPath)); // "Touch" the record to mark it as updated await this.todoTable.UpdateAsync(todoItem); return file; }
public async Task DeleteTaskAsync(TodoItem item) { try { //TodoViewModel.TodoItems.Remove(item); await todoTable.DeleteAsync(item); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"INVALID {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"ERROR {0}", e.Message); } }
public async Task SaveTaskAsync(TodoItem item) { if (item.Id == null) { await todoTable.InsertAsync(item); //TodoViewModel.TodoItems.Add(item); } else await todoTable.UpdateAsync(item); }
public async Task SaveTaskAsync(TodoItem item) { if (item.Id == null) { await todoTable.InsertAsync(item); } else { await todoTable.UpdateAsync(item); } }
async Task DeleteItem(TodoItem item) { await manager.DeleteTaskAsync(item); await LoadItems(); }
// Data methods private async Task AddItem(TodoItem item) { await manager.SaveTaskAsync(item); await LoadItems(); }