public static Book ParseSingleSearchResponse(GoogleBookSingleResponse response) { Book book = db.Books.FirstOrDefault(b => b.GoogleVolumeId == response.id); if (book != null) { book.Authors = GetAuthorString(response.volumeInfo.authors); book.Categories = GetCategoryString(response.volumeInfo.categories); return(book); } else { return(AddNewSingleBook(response)); } }
public static Book AddNewSingleBook(GoogleBookSingleResponse response) { Book book = new Book() { Id = Guid.NewGuid(), GoogleVolumeId = response.id, Description = response.volumeInfo.description, Title = response.volumeInfo.title, PageCount = response.volumeInfo.pageCount, Thumbnail = response.volumeInfo.imageLinks == null ? Constants.Placeholders.Thumbnail : response.volumeInfo.imageLinks.thumbnail }; book.Authors = GetAuthorString(response.volumeInfo.authors); AddBookAuthorJunctionEntries(book, response.volumeInfo.authors); book.Categories = GetCategoryString(response.volumeInfo.categories); AddBookTagJunctionEntries(book, response.volumeInfo.categories); db.Books.Add(book); db.SaveChanges(); return(book); }