Example #1
0
        /// <inheritdoc/>
        public void AddBook(BookInfo book)
        {
            if (book == null)
            {
                throw new ArgumentNullException(nameof(book), "Argument is null");
            }

            foreach (var itemBook in this.books)
            {
                if (book.Equals(itemBook))
                {
                    throw new ArgumentException($"The book is in the collection");
                }
            }

            this.Books.Add(book);
        }
        /// <inheritdoc/>
        public void AddBook(BookInfo book)
        {
            logger.Info("Adding new book in collection.");
            if (book == null)
            {
                throw new ArgumentNullException(nameof(book), "Argument is null.");
            }

            foreach (var itemBook in this.books)
            {
                if (book.Equals(itemBook))
                {
                    throw new ArgumentException($"The book is in the collection.");
                }
            }

            try
            {
                this.Books.Add(book);
            }
            catch (Exception ex)
            {
                logger.Info("Unhandled exception while adding new book:");
                logger.Info(ex.Message);
                logger.Error(ex.StackTrace);
                throw;
            }
            finally
            {
                if (this.Books.Contains(book))
                {
                    logger.Info("Book successfully added.");
                }
                else
                {
                    logger.Info("Book cannot be added.");
                }
            }
        }