TodoItemViewModel ToViewModel(TodoItem item) { var vm = new TodoItemViewModel(item); vm.Edit = navigator.NavigateCommand( "EditPage", p => p.Add("Item", item) ); vm.Delete = ReactiveCommand.CreateFromTask(async() => { var confirm = await this.dialogs.ConfirmAsync($"Are you sure you wish to delete '${item.Title}'"); if (confirm ?? false) { await this.todoService.Remove(item.Id); this.DoLoad(); } }); vm.MarkComplete = ReactiveCommand.CreateFromTask(async() => { if (item.CompletionDateUtc == null) { item.CompletionDateUtc = DateTime.UtcNow; } else { item.CompletionDateUtc = null; } await this.todoService.Save(item); vm.RaisePropertyChanged(nameof(vm.IsCompleted)); vm.RaisePropertyChanged(nameof(vm.IsOverdue)); }); return(vm); }
TodoItemViewModel ToViewModel(ITodoItem item) { var vm = new TodoItemViewModel(item); vm.Edit = navigator.NavigateCommand( "EditPage", p => p.Add("Item", item) ); vm.Delete = ReactiveCommand.CreateFromTask(async() => { var confirm = await this.dialogs.Confirm($"Are you sure you wish to delete '${item.Title}'"); if (confirm) { await this.data.Delete(item.Id); this.DoLoad(); } }); vm.MarkComplete = ReactiveCommand.CreateFromTask(async() => { if (item.CompletionDateUtc == null) { item.CompletionDateUtc = DateTime.UtcNow; } else { item.CompletionDateUtc = null; } await this.data.Update(item); vm.RaisePropertyChanged(nameof(vm.IsCompleted)); vm.RaisePropertyChanged(nameof(vm.IsOverdue)); // TODO: for unit testing later // TODO: cancel notification & geofence if completed }); return(vm); }