protected override void OnStartup(StartupEventArgs e) { var repository = new DefaultBlogPostRepository("http://localhost:54162"); var applicationContext = new ApplicationContext(repository); var mainWindow = new MainWindow(applicationContext); mainWindow.Show(); }
private async Task RemoveAuthorAsync(Author author, DefaultBlogPostRepository repository) { if (author == null) { return; } Int32 authorId = author.Id; await repository.DeleteAuthorAsync(authorId); OnRefreshContext(); }
public AuthorEditorContext(DefaultBlogPostRepository repository) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } this.repository = repository; AddAuthor = new ActionCommand(async() => await AddAuthorAsync(DetailedAuthor, repository)); RemoveAuthor = new ActionCommand(async() => await RemoveAuthorAsync(SelectedAuthor, repository)); DetailedAuthor = new DetailedAuthorContext(); }
public ApplicationContext(DefaultBlogPostRepository repository) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } BlogPostEditorContext = new BlogPostEditorContext(repository); AuthorEditorContext = new AuthorEditorContext(repository); BlogPostEditorContext.RefreshContext += (sender, args) => OnRefreshContext(); AuthorEditorContext.RefreshContext += (sender, args) => OnRefreshContext(); RefreshCommand = new ActionCommand(OnRefreshContext); OnRefreshContext(); }
public BlogPostEditorContext(DefaultBlogPostRepository repository) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } this.repository = repository; AssignCommand = new ActionCommand(async() => { if (SelectedAuthor == null || SelectedBlogPost == null) { return; } await repository.AssignAuthorToBlogPostAsync(SelectedBlogPost.Id, SelectedAuthor.Id); OnRefreshContext(); }); }
private async Task AddAuthorAsync(DetailedAuthorContext author, DefaultBlogPostRepository repository) { await repository.AddAuthorAsync(author.FullName); OnRefreshContext(); }