public bool CreateBook(List <int> authorsId, List <int> categoriesId, Book book)
        {
            var authors    = _bookContext.Authors.Where(a => authorsId.Contains(a.Id)).ToList();
            var categories = _bookContext.Categories.Where(c => categoriesId.Contains(c.Id)).ToList();

            foreach (var author in authors)
            {
                var bookAuthors = new BookAuthor
                {
                    Author = author,
                    Book   = book
                };

                _bookContext.Add(bookAuthors);
            }

            foreach (var category in categories)
            {
                var bookCategory = new BookCategory
                {
                    Category = category,
                    Book     = book
                };
                _bookContext.Add(bookCategory);
            }


            _bookContext.Add(book);

            return(Save());
        }
Example #2
0
 public bool CreateAuthor(Author author)
 {
     _authorContext.Add(author);
     return(Save());
 }
Example #3
0
 public bool CreateReviewer(Reviewer reviewer)
 {
     _context.Add(reviewer);
     return(Save());
 }