示例#1
0
        protected LibraryDTO GetBooksFromLibraryExpress(IUrlHttpClient urlHttpClient, IBookRepository bookRepository, BookFilter bookFilter)
        {
            try
            {
                var libraryRequest = GenerateLibraryBookRequest(bookFilter);

                //Go fetch from external service ExpressLibraryApi
                var libraryResponse = urlHttpClient.HttpGet(libraryRequest).Result;

                var libraryDto = ProcessExternalLibraryResponse(libraryResponse);

                if (libraryDto != null && libraryDto.Books != null && libraryDto.Books.Count > 0)
                {
                    try
                    {
                        var newLibraryDto = new LibraryDTO();

                        var ourbooks = bookRepository.AddBooks(libraryDto.Books);

                        newLibraryDto.Books      = ourbooks;
                        newLibraryDto.TotalBooks = ourbooks.Count;

                        return(newLibraryDto);
                    }
                    catch (Exception ex)
                    {
                        //TODO: Log this the exception information along with the method details to the database for Error tracing
                        //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point
                        return(null);
                    }
                }
                return(libraryDto);
            }
            catch (Exception ex)
            {
                //TODO: Log this the exception information along with the method details to the database for Error tracing
                //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point
                return(null);
            }
        }
示例#2
0
 public BookService(IBookRepository peopleRepository, IUrlHttpClient iUrlHttpClient)
 {
     _bookRepository = peopleRepository;
     _urlHttpClient  = iUrlHttpClient;
 }