Exemple #1
0
        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();
        }
Exemple #2
0
        private async Task RemoveAuthorAsync(Author author, DefaultBlogPostRepository repository)
        {
            if (author == null)
            {
                return;
            }

            Int32 authorId = author.Id;
            await repository.DeleteAuthorAsync(authorId);

            OnRefreshContext();
        }
Exemple #3
0
        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();
        }
Exemple #5
0
        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();
            });
        }
Exemple #6
0
        private async Task AddAuthorAsync(DetailedAuthorContext author, DefaultBlogPostRepository repository)
        {
            await repository.AddAuthorAsync(author.FullName);

            OnRefreshContext();
        }