public OrganizationViewModel(ISessionService applicationService) { this.WhenAnyValue(x => x.Organization, x => x.Username, (x, y) => x == null ? y : (string.IsNullOrEmpty(x.Name) ? x.Login : x.Name)) .Select(x => x ?? "Organization") .Subscribe(x => Title = x); this.WhenAnyValue(x => x.Organization.AvatarUrl) .Select(x => new GitHubAvatar(x)) .ToProperty(this, x => x.Avatar, out _avatar); GoToMembersCommand = ReactiveCommand.Create(); GoToMembersCommand .Select(_ => this.CreateViewModel <OrganizationMembersViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToTeamsCommand = ReactiveCommand.Create(); GoToTeamsCommand .Select(_ => this.CreateViewModel <TeamsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToFollowersCommand = ReactiveCommand.Create(); GoToFollowersCommand .Select(_ => this.CreateViewModel <UserFollowersViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToFollowingCommand = ReactiveCommand.Create(); GoToFollowingCommand .Select(_ => this.CreateViewModel <UserFollowingsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand .Select(_ => this.CreateViewModel <UserEventsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToGistsCommand = ReactiveCommand.Create(); GoToGistsCommand .Select(_ => this.CreateViewModel <UserGistsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <OrganizationRepositoriesViewModel>(); vm.Name = Username; NavigateTo(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { applicationService.GitHubClient.Organization.Team.GetAll(Username) .ToBackground(x => CanViewTeams = true); Organization = await applicationService.GitHubClient.Organization.Get(Username); }); }
public UserViewModel(ISessionService applicationService, IActionMenuFactory actionMenuService) { _applicationService = applicationService; ToggleFollowingCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue), t => ToggleFollowing()); _hasBlog = this.WhenAnyValue(x => x.User.Blog) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.HasBlog); _avatar = this.WhenAnyValue(x => x.User.AvatarUrl) .Select(x => new GitHubAvatar(x)) .ToProperty(this, x => x.Avatar); GoToGistsCommand = ReactiveCommand.Create(); GoToGistsCommand .Select(_ => this.CreateViewModel <UserGistsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToRepositoriesCommand = ReactiveCommand.Create(); GoToRepositoriesCommand .Select(_ => this.CreateViewModel <UserRepositoriesViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToOrganizationsCommand = ReactiveCommand.Create(); GoToOrganizationsCommand .Select(_ => this.CreateViewModel <OrganizationsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand .Select(_ => this.CreateViewModel <UserEventsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToFollowingCommand = ReactiveCommand.Create(); GoToFollowingCommand .Select(_ => this.CreateViewModel <UserFollowingsViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToFollowersCommand = ReactiveCommand.Create(); GoToFollowersCommand .Select(_ => this.CreateViewModel <UserFollowersViewModel>()) .Select(x => x.Init(Username)) .Subscribe(NavigateTo); GoToWebsiteCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasBlog)); GoToWebsiteCommand .Select(_ => this.CreateViewModel <WebBrowserViewModel>()) .Select(x => x.Init(User.Blog)) .Subscribe(NavigateTo); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue), sender => { var menu = actionMenuService.Create(); menu.AddButton(IsFollowing.Value ? "Unfollow" : "Follow", ToggleFollowingCommand); return(menu.Show(sender)); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { if (!IsLoggedInUser) { applicationService.GitHubClient.User.Followers.IsFollowingForCurrent(Username) .ToBackground(x => IsFollowing = x); } User = await applicationService.GitHubClient.User.Get(Username); }); }