예제 #1
0
        public void TakeBook(List <Book> Books, uint Id, LibraryReader libReader)
        {
            libReader.PickupDate = GetCurrentDate();
            var takenBooks = Books.Where(x => x.Reader != null).ToList();

            if (Books.Count() > 0)
            {
                if (takenBooks.Where(x => x.Reader.Equals(libReader)).Count() >= TakenBooksLimit)
                {
                    throw new TakenBooksLimitException();
                }
                else
                {
                    var dateSpan = Period.Between(libReader.PickupDate, libReader.ReturnDate, PeriodUnits.Months);
                    if (dateSpan.Months > BorrowMonthPeriodLimit)
                    {
                        throw new TakeDatePeriodException();
                    }
                    else
                    {
                        foreach (var book in Books.Where(b => b.Id == Id))
                        {
                            book.Reader = libReader;
                        }
                        Console.WriteLine("Succesfully took the book !\n");
                    }
                }
            }
            else
            {
                throw new EmptyLibraryException();
            }
        }
예제 #2
0
        public void ReturnBook(List <Book> Books, uint Id, LibraryReader libReader)
        {
            var returnedBook = Books.SingleOrDefault(b => b.Id == Id);

            if (Books.Count() > 0)
            {
                if (returnedBook.Reader != null && returnedBook.Reader.Equals(libReader))
                {
                    var currentDate = GetCurrentDate();
                    if (returnedBook.Reader.ReturnDate.CompareTo(currentDate) < 0)
                    {
                        Console.WriteLine("You're late to return the book ! -rep.\n");
                    }
                    foreach (var book in Books.Where(b => b.Id == Id))
                    {
                        book.Reader = null;
                    }
                    Console.WriteLine("Succesfully returned the book !\n");
                }
                else
                {
                    throw new NotReadersBookException();
                }
            }
            else
            {
                throw new EmptyLibraryException();
            }
        }
예제 #3
0
파일: Book.cs 프로젝트: iraqnroll/VismaTask
 public Book(string Name, string Author, string Category, string Language, LocalDate Publication, string Isbn)
 {
     this.Name            = Name;
     this.Author          = Author;
     this.Category        = Category;
     this.Language        = Language;
     this.PublicationDate = Publication;
     this.Isbn            = Isbn;
     this.Reader          = null;
 }