Example #1
0
        public void GiveBook(int bookId, int userId)
        {
            var book = _bookRepository.GetById(bookId);

            if (book == null)
            {
                throw new NotFoundException(nameof(Book));
            }

            if (book.Available < 1)
            {
                throw new NoAvailableBooksException(book.Title);
            }

            var user = _readerRepository.GetById(userId);

            if (user == null)
            {
                throw new NotFoundException(nameof(Reader));
            }

            _readerRepository.AddBook(user, book);
            book.Available--;
            _bookRepository.Update(book);
        }