Beispiel #1
0
        public void Update(BookGetViewModel bookView)
        {
            List <AuthorInBook> bookInAuthor = _authorInBookRepository.GetBook(bookView.Book.Id).ToList();

            if (bookInAuthor != null)
            {
                List <AuthorInBook> updateBook = CreateAuthorInBook(bookView, bookInAuthor.First().Id);

                _authorInBookRepository.Update(updateBook);
            }
        }
Beispiel #2
0
        public BookGetViewModel GetBook(int id)
        {
            List <AuthorInBook> books = _authorInBookRepository.GetBook(id).ToList();
            var bookView = new BookGetViewModel();

            if (books != null)
            {
                bookView = books.GroupBy(x => x.Book.Id).Select(x => new BookGetViewModel()
                {
                    Book    = x.First().Book,
                    Authors = x.Select(z => z.Author).ToList()
                }).First();
            }
            return(bookView);
        }
Beispiel #3
0
        private List <AuthorInBook> CreateAuthorInBook(BookGetViewModel bookView, int IdAuthorInBook)
        {
            var updateBook = new List <AuthorInBook>();

            if (bookView.Authors.Count != 0)
            {
                foreach (Author author in bookView.Authors)
                {
                    updateBook.Add(new AuthorInBook {
                        Author = author, Book = bookView.Book, Id = IdAuthorInBook
                    });
                }
            }
            if (bookView.Authors.Count == 0)
            {
                updateBook.Add(new AuthorInBook {
                    Book = bookView.Book
                });
            }
            return(updateBook);
        }