public OrganizationViewModel(IApplicationService applicationService) { GoToMembersCommand = ReactiveCommand.Create(); GoToMembersCommand.Subscribe(_ => { var vm = CreateViewModel <OrganizationMembersViewModel>(); vm.OrganizationName = Name; ShowViewModel(vm); }); GoToTeamsCommand = ReactiveCommand.Create(); GoToTeamsCommand.Subscribe(_ => { var vm = CreateViewModel <TeamsViewModel>(); vm.OrganizationName = Name; ShowViewModel(vm); }); GoToFollowersCommand = ReactiveCommand.Create(); GoToFollowersCommand.Subscribe(_ => { var vm = CreateViewModel <UserFollowersViewModel>(); vm.Username = Name; ShowViewModel(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = Name; ShowViewModel(vm); }); GoToGistsCommand = ReactiveCommand.Create(); GoToGistsCommand.Subscribe(_ => { var vm = CreateViewModel <UserGistsViewModel>(); vm.Username = Name; ShowViewModel(vm); }); GoToRepositoriesCommand = ReactiveCommand.Create(); GoToRepositoriesCommand.Subscribe(_ => { var vm = CreateViewModel <OrganizationRepositoriesViewModel>(); vm.Name = Name; ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => this.RequestModel(applicationService.Client.Organizations[Name].Get(), t as bool?, response => Organization = response.Data)); }
public UserViewModel(string username, IApplicationService applicationService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); GoToFollowersCommand.Subscribe(_ => NavigateTo(new UserFollowersViewModel(username))); GoToFollowingCommand.Subscribe(_ => NavigateTo(new UserFollowingsViewModel(username))); GoToEventsCommand.Subscribe(_ => NavigateTo(new UserEventsViewModel(username))); GoToGroupsCommand.Subscribe(_ => NavigateTo(new GroupsViewModel(username))); GoToRepositoriesCommand.Subscribe(_ => NavigateTo(new UserRepositoriesViewModel(username))); this.WhenAnyValue(x => x.User.Website) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.IsWebsiteAvailable, out _isWebsiteAvailable); this.WhenAnyValue(x => x.User.DisplayName) .Select(x => string.Equals(x, username) ? null : x) .ToProperty(this, x => x.DisplayName, out _displayName); GoToWebsiteCommand = ReactiveCommand.Create( () => NavigateTo(new WebBrowserViewModel(User.Website)), this.WhenAnyValue(x => x.IsWebsiteAvailable)); ShouldShowGroups = string.Equals(username, applicationService.Account.Username, StringComparison.OrdinalIgnoreCase); Title = username; LoadCommand = ReactiveCommand.CreateFromTask(async t => { if (!string.Equals(applicationService.Account.Username, username, StringComparison.OrdinalIgnoreCase)) { applicationService.Client.Groups.GetGroups(username) .ToObservable() .Select(_ => true) .Catch(Observable.Return(false)) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => ShouldShowGroups = x); } User = await applicationService.Client.Users.GetUser(username); }); }
public TeamViewModel( string name, IApplicationService applicationService = null) { applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); Title = name; GoToFollowersCommand.Subscribe(_ => NavigateTo(new TeamFollowersViewModel(name))); GoToFollowingCommand.Subscribe(_ => NavigateTo(new TeamFollowingsViewModel(name))); GoToMembersCommand.Subscribe(_ => NavigateTo(new TeamMembersViewModel(name))); GoToGroupsCommand.Subscribe(_ => NavigateTo(new GroupsViewModel(name))); GoToEventsCommand.Subscribe(_ => NavigateTo(new UserEventsViewModel(name))); GoToRepositoriesCommand.Subscribe(_ => NavigateTo(new UserRepositoriesViewModel(name))); this.WhenAnyValue(x => x.Team.DisplayName) .Select(x => string.Equals(x, name) ? null : x) .ToProperty(this, x => x.DisplayName, out _displayName); LoadCommand = ReactiveCommand.CreateFromTask(async _ => { Team = await applicationService.Client.Teams.Get(name); }); }
public UserViewModel(IApplicationService applicationService) { _applicationService = applicationService; ToggleFollowingCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue), t => ToggleFollowing()); GoToGistsCommand = ReactiveCommand.Create(); GoToGistsCommand.Subscribe(_ => { var vm = CreateViewModel <UserGistsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToRepositoriesCommand = ReactiveCommand.Create(); GoToRepositoriesCommand.Subscribe(_ => { var vm = CreateViewModel <UserRepositoriesViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToOrganizationsCommand = ReactiveCommand.Create(); GoToOrganizationsCommand.Subscribe(_ => { var vm = CreateViewModel <OrganizationsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToFollowingCommand = ReactiveCommand.Create(); GoToFollowingCommand.Subscribe(_ => { var vm = CreateViewModel <UserFollowingsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToFollowersCommand = ReactiveCommand.Create(); GoToFollowersCommand.Subscribe(_ => { var vm = CreateViewModel <UserFollowersViewModel>(); vm.Username = Username; ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { this.RequestModel(applicationService.Client.AuthenticatedUser.IsFollowing(Username), t as bool?, x => IsFollowing = x.Data).FireAndForget(); return(this.RequestModel(applicationService.Client.Users[Username].Get(), t as bool?, response => User = response.Data)); }); }