private void CreateCommands() { Add = ReactiveCommand.Create(ExecuteAdd); //get existing jobs and tags/instruments Load = ReactiveCommand.CreateFromTask(async _ => { var dataUpdateJobs = _client.GetaDataUpdateJobs(); var econReleaseUpdateJobs = _client.GetEconomicReleaseUpdateJobs(); var dividendUpdateJobs = _client.GetDividendUpdateJobs(); var earningsUpdateJobs = _client.GetEarningsUpdateJobs(); var tags = _client.GetTags(); var instruments = _client.GetInstruments(); var econReleaseSources = _client.GetEconomicReleaseDataSources(); var dividendSources = _client.GetDividendDataSources(); var earningsSources = _client.GetEarningsDataSources(); await Task.WhenAll(dataUpdateJobs, econReleaseUpdateJobs, dividendUpdateJobs, tags, instruments, econReleaseSources, dividendSources, earningsUpdateJobs, earningsSources).ConfigureAwait(false); var responses = new ApiResponse[] { dataUpdateJobs.Result, econReleaseUpdateJobs.Result, dividendUpdateJobs.Result, tags.Result, instruments.Result, econReleaseSources.Result, dividendSources.Result, earningsUpdateJobs.Result, earningsSources.Result }; if (await responses.DisplayErrors(this, DialogCoordinator).ConfigureAwait(true)) { return(null); } Tags.AddRange(tags.Result.Result); Instruments.AddRange(instruments.Result.Result); EconomicReleaseDataSources.AddRange(econReleaseSources.Result.Result); DividendDataSources.AddRange(dividendSources.Result.Result); EarningsDataSources.AddRange(earningsSources.Result.Result); var jobs = new List <IJobSettings>(); jobs.AddRange(dataUpdateJobs.Result.Result); jobs.AddRange(econReleaseUpdateJobs.Result.Result); jobs.AddRange(dividendUpdateJobs.Result.Result); jobs.AddRange(earningsUpdateJobs.Result.Result); return(jobs); }); Load.Subscribe(jobs => { if (jobs == null) { return; } foreach (var job in jobs) { Jobs.Add(GetJobViewModel(job)); } }); //Delete job var deleteCanExecute = this .WhenAnyValue(x => x.SelectedJob) .Select(x => x != null && !string.IsNullOrEmpty(x.PreChangeName)); Delete = ReactiveCommand.CreateFromTask(async _ => { //Give a dialog to confirm the deletion MessageDialogResult dialogResult = await DialogCoordinator.ShowMessageAsync(this, "Delete Job", string.Format("Are you sure you want to delete {0}?", SelectedJob.Name), MessageDialogStyle.AffirmativeAndNegative); if (dialogResult != MessageDialogResult.Affirmative) { return; } //If the name has changed but hasn't been saved, we change it back to be in sync with the server SelectedJob.Name = SelectedJob.PreChangeName; //Request deletion var response = await SelectedJob.Delete.Execute(); if (await response.DisplayErrors(this, DialogCoordinator)) { return; } //if it was successful, remove the VM from the list Jobs.Remove(SelectedJob); SelectedJob = null; }, deleteCanExecute); }