public CreateFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory) { Title = "Create File"; this.WhenAnyValue(x => x.Name) .Subscribe(x => CommitMessage = "Created " + x); GoToCommitMessageCommand = ReactiveCommand.Create( this.WhenAnyValue(x => x.Name, x => !string.IsNullOrEmpty(x))); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => { var content = Content ?? string.Empty; var path = System.IO.Path.Combine(Path ?? string.Empty, Name); var request = new Octokit.CreateFileRequest(CommitMessage, content) { Branch = Branch }; using (alertDialogFactory.Activate("Commiting...")) return await sessionService.GitHubClient.Repository.Content.CreateFile(RepositoryOwner, RepositoryName, path, request); }); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) return true; return await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?"); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }
public CreateFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory) { Title = "Create File"; this.WhenAnyValue(x => x.Name) .Subscribe(x => CommitMessage = "Created " + x); _canCommit = this.WhenAnyValue(x => x.Name) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.CanCommit); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => { var content = Content ?? string.Empty; var path = System.IO.Path.Combine(Path ?? string.Empty, Name); var request = new Octokit.CreateFileRequest(CommitMessage, content) { Branch = Branch }; using (alertDialogFactory.Activate("Commiting...")) return(await sessionService.GitHubClient.Repository.Content.CreateFile(RepositoryOwner, RepositoryName, path, request)); }); SaveCommand.Subscribe(x => Dismiss()); DismissCommand = ReactiveCommand.CreateAsyncTask(async t => { if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) { return(true); } return(await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?")); }); DismissCommand.Where(x => x).Subscribe(_ => Dismiss()); }