private async Task AddExecuteAsync() { var newId = await Navigator.AddAsync <Domain.Person>(); if (newId.HasValue) { await Load.ExecuteAsync(newId.Value); } }
private async Task RemoveExecuteAsync() { if (SelectedItem == null || !SelectedItem.Id.HasValue) { throw new InvalidOperationException("Must have a selected item with an Id to delete!"); } await Repository.Delete(SelectedItem.Id.Value); await Load.ExecuteAsync(null); }
private async Task EditExecuteAsync() { if (SelectedItem == null || !SelectedItem.Id.HasValue) { throw new InvalidOperationException("Must have a selected item with an Id to edit!"); } var edited = await Navigator.EditAsync <Domain.Person>(SelectedItem.Id.Value); if (edited) { await Load.ExecuteAsync(SelectedItem.Id.Value); } }
public MainWindowViewModel() { ModalController = new ModalController(); _repo = PackageRepositoryFactory.Default.CreateRepository("https://www.nuget.org/api/v2/"); _random = new Random(); Page = 0; PageSize = 25; HasError = false; Load = ReactiveCommand.CreateAsyncObservable(_ => SearchImpl(Page, PageSize), RxApp.TaskpoolScheduler); Load.ThrownExceptions.Subscribe(HandleSearchError); Load.IsExecuting.ObserveOn(RxApp.MainThreadScheduler).ToPropertyEx(this, x => x.IsBusy); Load.ToReadOnlyList(GetPackageCardViewModel) .ObserveOn(RxApp.MainThreadScheduler) .ToPropertyEx(this, x => x.Packages, new List <PackageCardViewModel>().AsReadOnly()); var canNext = this.WhenAny(x => x.IsBusy, busy => !busy.Value); Next = ReactiveCommand.CreateAsyncObservable(canNext, _ => { Page = Page + 1; return(Load.ExecuteAsync()); }); Next.ThrownExceptions.Subscribe(ex => this.Log().Error($"Error occurred: {ex.ToString()}")); var canPrevious = this.WhenAny(x => x.IsBusy, x => x.Page, (busy, page) => !busy.Value && page.Value > 0); Previous = ReactiveCommand.CreateAsyncObservable(canPrevious, _ => { Page = Page - 1; return(Load.ExecuteAsync()); }); Previous.ThrownExceptions.Subscribe(ex => this.Log().Error($"Error occurred: {ex.ToString()}")); ShowDialog = ReactiveCommand.Create(); ShowDialog.Subscribe(_ => ModalController.ShowModal(new FirstModalViewModel())); this.WhenActivated(d => { d(Load.ExecuteAsync().Subscribe()); }); }