Example #1
0
        public async Task <Book> AddByISBNAsync(string isbn)
        {
            //check if an author exists for this ISBN
            var authorName = await ISBNService.GetAuthorNameByISBNAsync(isbn);

            var author = await AuthorRepository.CreateOrGetByNameAsync(authorName);

            var book = await ISBNService.GetByISBNAsync(isbn);

            book.SetAuthor(author);

            //TODO: this should be represented in a unit of work
            await author.AddBookIfNotAlreadyPresentAsync(book);

            //commit all the changes
            await AuthorRepository.UpdateAuthorAsync(author);

            await BookStorage.WriteBookAsync(book);

            return(book);
        }