public EditorViewModel(IScreen screen) { HostScreen = screen; var clientsObs = GetClients(); var iLinksObs = GetILinks(); //join both data streams, and make a dictionary out of them when they return clientsObs.Join( iLinksObs, _ => Observable.Never<Unit>(), _ => Observable.Never<Unit>(), (clientList, iLinksList) => clientList.Join( iLinksList, c => c.ID, i => i.Client_ID, (c, i) => new { Client = c, MetroiLinks = i }) ).Subscribe(r => { MetroiLinks = r.ToDictionary(k => k.Client, v => v.MetroiLinks); Clients = new ReactiveList<iLinks.Data.Client>(r.Select(x => x.Client).OrderBy(x => x.Name)); }); //Filter the clients list based on what the filter text is this.ObservableForProperty(x => x.FilterClientsText) .Where(x => x != null) .Select(x => x.Value) .Subscribe(filterText => { if (filterText.Length == 0) Clients = new ReactiveList<iLinks.Data.Client>(MetroiLinks.Select(m => m.Key).ToList()); else { Clients = new ReactiveList<iLinks.Data.Client>( MetroiLinks.Select(m => m.Key) .ToList() .Where(c => c.ID.ToString().Contains(filterText) || c.Name.ToUpper().Contains(filterText.ToUpper())) .ToList()); } }); //On SelectedClient Changed this.ObservableForProperty(x => x.SelectedClient) .Select(x => x.Value) .Subscribe(client => { if (client != null) { MetroiLinksViewModel.MetroiLink = MetroiLinks[client]; } }); //Clear the filter on the ClearFilterTextcommand ClearFilterTextCommand = new ReactiveCommand(); ClearFilterTextCommand.Subscribe(x => FilterClientsText = ""); SaveILinksCommand = new ReactiveCommand(this.WhenAny(x => x.SelectedClient, x => x.Value != null)); SaveILinksCommand.Subscribe(x => { var repo = new MetroiLinksRepo(); repo.Update(MetroiLinksViewModel.MetroiLink); MessageBox.Show("Saved"); }); MetroiLinksViewModel = new MetroiLinksViewModel(); MessageBus.Current.Listen<SortableObservableCollection<iLinks.Data.Page>>().Subscribe(x => { var cpRepo = new CommunityProfilesRepo(); var currentSelectedILink = MetroiLinksViewModel.MetroiLink; cpRepo.UpdateCommunityProfiles(currentSelectedILink.Client_ID, x); MetroiLinksViewModel.MetroiLink = null; MetroiLinksViewModel.MetroiLink = currentSelectedILink; }); }
private IObservable<List<iLinks.Data.Metro_iLink>> GetILinks() { var repo = new MetroiLinksRepo(); return Observable.Return(repo.GetAll().ToList()); }