Пример #1
0
        /// <summary>
        /// Adds a new book to storage
        /// </summary>
        /// <param name="newBook">book to add</param>
        public void AddBook(Book newBook)
        {
            if (newBook == null)
            {
                throw new ArgumentNullException("Book must be not null");
            }

            List <Book> books = new List <Book>(storage.LoadFromStorage());

            if (books.Contains(newBook))
            {
                throw new BookExistsInStorageException("Book is already exists in storage");
            }
            books.Add(newBook);
            storage.SaveToStorage(books);
            logger.Debug("Book was added");
        }
Пример #2
0
        /// <summary>
        /// Saves to storage.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <exception cref="ArgumentNullException">storage</exception>
        public void SaveToStorage(IBookListStorage storage)
        {
            Logger.Info($"Saving to storage started!");
            if (ReferenceEquals(storage, null))
            {
                Logger.Error($"{nameof(storage)} is null!");
                throw new ArgumentNullException($"{nameof(storage)} is null");
            }

            storage.SaveToStorage(BookList);
            Logger.Info($"Saving to storage completed!");
        }