コード例 #1
0
        private static async Task ReadChapterAsync()
        {
            WriteLine(nameof(ReadChapterAsync));
            var client   = new BookChapterClient(Addresses.BaseAddress);
            var chapters = await client.GetAllAsync(Addresses.BooksApi);

            Guid        id      = chapters.First().Id;
            BookChapter chapter = await client.GetAsync(Addresses.BooksApi + id);

            WriteLine($"{chapter.Number} {chapter.Title}");
            WriteLine();
        }
コード例 #2
0
        private static async Task ReadChaptersAsync()
        {
            WriteLine(nameof(ReadChaptersAsync));
            var client = new BookChapterClient(Addresses.BaseAddress);
            IEnumerable <BookChapter> chapters = await client.GetAllAsync(Addresses.BooksApi);

            foreach (BookChapter chapter in chapters)
            {
                WriteLine(chapter.Title);
            }
            WriteLine();
        }
コード例 #3
0
        private static async Task RemoveChapterAsync()
        {
            WriteLine(nameof(RemoveChapterAsync));
            var client   = new BookChapterClient(Addresses.BaseAddress);
            var chapters = await client.GetAllAsync(Addresses.BooksApi);

            var chapter = chapters.SingleOrDefault(c => c.Title == "ASP.NET Web Forms");

            if (chapter != null)
            {
                await client.DeleteAsync(Addresses.BooksApi + chapter.Id);

                WriteLine($"removed chapter {chapter.Title}");
            }

            WriteLine();
        }
コード例 #4
0
        private static async Task UpdateChapterAsync()
        {
            WriteLine(nameof(UpdateChapterAsync));
            var client   = new BookChapterClient(Addresses.BaseAddress);
            var chapters = await client.GetAllAsync(Addresses.BooksApi);

            var chapter = chapters.SingleOrDefault(c => c.Title == "Windows Store Apps");

            if (chapter != null)
            {
                chapter.Number = 32;
                chapter.Title  = "Windows Apps";
                await client.PutAsync(Addresses.BooksApi + chapter.Id, chapter);

                WriteLine($"updated chapter {chapter.Title}");
            }

            WriteLine();
        }