Beispiel #1
0
        // Выдача книги
        public void GiveBook(Subscriber sub, Book book)
        {
            int countsub = 0;

            foreach (Subscriber subscriber in subscribers)
            {
                if (subscriber.Name == sub.Name && subscriber.Phone == sub.Phone)
                {
                    countsub++;
                }
            }
            if (countsub == 0)
            {
                subscribers.Add(sub);
                AddSubHandler?.Invoke(this, sub);
            }

            if (sub.OverdueBooks().Count == 0 && sub.ListBooks().Count < 5 && (sub.HasRarityBook == false || (sub.HasRarityBook == true && book.IsRarity == false)))
            {
                bool hasBook = false;
                for (int i = 0; i < books.Count; i++)
                {
                    if (books[i] == book)
                    {
                        books.Remove(book);
                        hasBook = true;
                        break;
                    }
                }
                if (!hasBook)
                {
                    Console.WriteLine("Пользователь {0}, книги {1} в библиотеке нет", sub.Name, book.Author + " " + book.Name);
                    return;
                }
                book.Sub   = sub;
                book.Begin = DateTime.Now;
                sub.Books.Add(book);
                ChangeStateHandler?.Invoke(this, $"Change State Book: {book.Author} - {book.Name} was given to {sub.Name} - {sub.Phone}");
                if (book.IsRarity)
                {
                    sub.HasRarityBook = true;
                }
            }
            else
            {
                Console.WriteLine("Пользователь {0}, сдайте {1} книги", sub.Name, sub.OverdueBooks().Count > 0 ? "просроченные" : "лишние");
            }
        }
Beispiel #2
0
 public void ReturnBook(Subscriber sub, Book book)
 {
     sub.ReturnBook(this, book);
     ChangeStateHandler?.Invoke(this, $"Change State Book: {book.Author} - {book.Name} was return to Library");
 }