public PullRequestViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory) : base(applicationService, markdownService, actionMenuService, alertDialogFactory) { this.WhenAnyValue(x => x.Id) .Subscribe(x => Title = "Pull Request #" + x); this.WhenAnyValue(x => x.PullRequest.HtmlUrl) .ToProperty(this, x => x.HtmlUrl, out _htmlUrl); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); _canMerge = canMergeObservable.CombineLatest( this.WhenAnyValue(x => x.PushAccess), (x, y) => x && y) .ToProperty(this, x => x.CanMerge); _commentsCount = this.WhenAnyValue(x => x.Issue.Comments, x => x.Comments.Count, (x, y) => x + y) .ToProperty(this, x => x.CommentCount); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { using (alertDialogFactory.Activate("Merging...")) { var req = new MergePullRequest { Message = MergeComment }; var response = await applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) { throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); } await LoadCommand.ExecuteAsync(); } }); var canGoToCommits = this.WhenAnyValue(x => x.PullRequest.Commits).Select(x => x > 0); GoToCommitsCommand = ReactiveCommand.Create(canGoToCommits); GoToCommitsCommand .Select(x => this.CreateViewModel <PullRequestCommitsViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName, Id)) .Subscribe(NavigateTo); var canGoToFiles = this.WhenAnyValue(x => x.PullRequest.ChangedFiles).Select(x => x > 0); GoToFilesCommand = ReactiveCommand.Create(canGoToFiles); GoToFilesCommand .Select(x => this.CreateViewModel <PullRequestFilesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName, Id, PullRequest.Head.Sha)) .Do(x => x.CommentCreated.Subscribe(AddComment)) .Subscribe(NavigateTo); }
private async Task ExecuteChangeRoleAsync() { var popup = await ApplicationService.OpenPopup <ChangeRoleWindowVm>(SelectedItem.GetRole()); if (popup.IsValidated) { await HandleMessageBoxError.ExecuteAsync(async() => { await Task.Run(() => ApplicationService.Command <ChangeRole>().Execute(SelectedItem.GetId(), popup.Role)); await LoadCommand.ExecuteAsync(); }); } }
private async Task ExecuteCreateSessionAsync(AppointmentItemEventArgs arg) { if (!Security[UserRole.Manager]) { MessageBox.Show("Vous n'avez pas le droit d'ajouter une session.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); return; } var vm = await _applicationService.OpenPopup <CreateSessionWindowVm>(new AppointmentItem(arg.Appointment.Start, arg.Appointment.Duration.Days, null, null, null, 0, null)); if (vm.IsValidated) { await LoadCommand.ExecuteAsync(); } }