private void ResetAuthors(int bookId, IEnumerable <AuthorInBook> authorInBookList) { var authorInBookRepo = new AuthorInBookRepository(dapperConnectionFactory); authorInBookRepo.GetByBookId(bookId).ToList().ForEach(ainb => authorInBookRepo.Delete(ainb) ); authorInBookList?.ToList().ForEach(ainb => { authorInBookRepo.Create(new AuthorInBook { Book_Id = bookId, Author_Id = ainb.Author_Id }); }); }
private IEnumerable <GetBookResponseModel> ToResponseModel(IEnumerable <Book> source) { var authorInBookRepository = new AuthorInBookRepository(dapperConnectionFactory); var publishedBookRepository = new PublishedBookRepository(dapperConnectionFactory); IEnumerable <GetBookResponseModel> response = source.Select(book => { return(new GetBookResponseModel { Id = book.Id, AdditionalData = book.AdditionalData, Capation = book.Capation, ISBN = book.ISBN, Authors = authorInBookRepository.GetAuthorInBookResponseModelByBookId(book.Id), PublishedBooks = publishedBookRepository.GetPublishedBookByBookId(book.Id) }); }); return(response); }
private IEnumerable <GetAuthorResponseModel> ToResponseModel(IEnumerable <Author> source) { var authorInBookRepository = new AuthorInBookRepository(dapperConnectionFactory); IEnumerable <GetAuthorResponseModel> response = source.Select(author => { return(new GetAuthorResponseModel { Id = author.Id, DateOfBirth = author.DateOfBirth, DateOfDeath = author.DateOfDeath, FirstName = author.FirstName, Patronymic = author.Patronymic, SecondName = author.SecondName, Books = authorInBookRepository.GetAuthorInBookResponseModelByAuthorId(author.Id) }); }); return(response); }
public GetAuthorResponseModel GetAuthorResponseModel(int id) { var authorInBookRepo = new AuthorInBookRepository(dapperConnectionFactory); Author author = base.Get(id); IEnumerable <AuthorInBook> ainbList = authorInBookRepo.GetByAuthorId(id); GetAuthorResponseModel response = new GetAuthorResponseModel { DateOfBirth = author.DateOfBirth, DateOfDeath = author.DateOfDeath, FirstName = author.FirstName, Id = author.Id, Patronymic = author.Patronymic, SecondName = author.SecondName, Books = authorInBookRepo.GetAuthorInBookResponseModelByAuthorId(author.Id) }; return(response); }