public void Execute(CreateAuthorDto request)
        {
            _validator.ValidateAndThrow(request);

            var author = new Author
            {
                Id         = request.Id,
                FirstName  = request.FirstName,
                LastName   = request.LastName,
                Birth      = request.Birth,
                BirthPlace = request.BirthPlace
            };

            foreach (var item in request.AuthorBooks)
            {
                // var book = _context.Books.Find(item.BookId);

                author.AuthorBooks.Add(new BookAuthor
                {
                    BookId   = item.BookId,
                    AuthorId = author.Id
                });
            }

            _context.Authors.Add(author);
            _context.SaveChanges();
        }
Esempio n. 2
0
        public void Execute(AuthorDto request)
        {
            _validator.ValidateAndThrow(request);

            var author = _mapper.Map <Author>(request);


            _context.Authors.Add(author);
            _context.SaveChanges();
        }