コード例 #1
0
ファイル: Library.cs プロジェクト: IuriiAksenov/Library
        /// <summary>
        /// Gives instance of book to the subscriber and sets a specific time
        /// </summary>
        /// <param name="subscriber"></param>
        /// <param name="book"></param>
        public void SubscribeTheBookToTheSubscriber(Subscriber subscriber, Book book, DateTime subscribingTime)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException("subsriber", "Sibscriber is null");
            }
            if (book == null)
            {
                throw new ArgumentNullException("book", "Book is null");
            }
            if (subscriber.GetTakenBooks().Count() >= 5)
            {
                throw new SubscribingException("У абонента превышен лимит книг", subscriber, book);
            }
            if (subscriber.GetOverdueTakenBooks().Any())
            {
                throw new SubscribingException("У абонента есть просроченные книги", subscriber, book);
            }
            if (book.BookSubscriber != null)
            {
                throw new SubscribingException("Книга уже у другого абонента", subscriber, book);
            }
            if (book.Rare && subscriber.GetRareBooks().Any())
            {
                throw new SubscribingException("У абонента уже есть редкая книга", subscriber, book);
            }

            book.Subscribe(subscriber, subscribingTime);
            subscriber.AddBook(book);

            BookStateChanged?.Invoke(this, new BookStateChangedEventArgs(book, BusinessLayer.BookStateChanged.Subscribing, true, "Книга выдана абоненту."));

            //BookStateChanged?.Invoke(this, new BookStateChangedEventArgs(book, BusinessLayer.BookStateChanged.Subscribing, false, "Книга не выдана абоненту, так как редкая книга уже имеется у абонента."));
        }
コード例 #2
0
ファイル: Library.cs プロジェクト: IuriiAksenov/Library
        /// <summary>
        /// Gets instance of the book from the subscriber and indocated, that this book in library
        /// </summary>
        /// <param name="subscriber"></param>
        /// <param name="book"></param>
        public void UnsubscribeTheBookFromTheSubscriber(Subscriber subscriber, Book book)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException("subsriber", "Sibscriber is null");
            }
            if (book == null)
            {
                throw new ArgumentNullException("book", "Book is null");
            }

            if (!subscriber.GetTakenBooks().Any(x => x == book))
            {
                //BookStateChanged?.Invoke(this, new BookStateChangedEventArgs(book, BusinessLayer.BookStateChanged.Unsubscribing, false, "Книга не принята от абонента"));
                throw new UnsubscribingException("Subscriber does not have trasmitted book in taken books", subscriber, book);
            }

            book.Unsubscribe();
            subscriber.RemoveBook(book);

            BookStateChanged?.Invoke(this, new BookStateChangedEventArgs(book, BusinessLayer.BookStateChanged.Unsubscribing, true, "Книга принята от абонента"));
        }