Beispiel #1
0
 /// <summary>
 /// Method to make a loan of a book for a member.
 /// </summary>
 /// <param name="member">Member that makes the loan.</param>
 /// <param name="book">Book the member wants to loan.</param>
 public void MakeLoan(Member member, Book book)
 {
     if (null == bookRepository.Find(book.ISBN))
     {
         throw new ArgumentException("No book wit ISBN: " + book.ISBN + " found in database.");
     }
     else
     {
         List <int> noOfCopiesOnLoan = loanRepository.All().
                                       Where(loan => loan.TimeOfReturn == null).
                                       Where(loan => loan.Copy.Book.ISBN == book.ISBN).
                                       Select(loan => loan.Copy.ID).
                                       ToList();
         BookCopy copyToLoan = bookCopyRepository.All().
                               Where(c => false == noOfCopiesOnLoan.Contains(c.ID)).
                               Where(c => c.Book.ISBN == book.ISBN).
                               FirstOrDefault();
         if (null == copyToLoan)
         {
             throw new ArgumentException("No bookcopy available for Title: " + book.Title + ".");
         }
         else
         {
             MakeLoan(member, copyToLoan);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Method to add a book to the database.
 /// </summary>
 /// <param name="book">Book</param>
 public void AddBook(Book book)
 {
     if (null != bookRepository.Find(book.ISBN))
     {
         throw new ArgumentException("Trying to add aready existing book according to ISBN no: " + book.ISBN + ".");
     }
     bookRepository.Add(book);
     Updated.Invoke(this, new EventArgs());
 }
Beispiel #3
0
 /// <summary>
 /// Method to add a new copy of an existing book.
 /// </summary>
 /// <param name="book">Book to add a copy too.</param>
 public void AddBookCopy(Book book)
 {
     if (null == bookRepository.Find(book.ISBN))
     {
         throw new ArgumentException("Book with given Title: " + book.Title + " and ISBN: " + book.ISBN + " does not exist in the database.");
     }
     bookCopyRepository.Add(new BookCopy()
     {
         Book = book
     });
     Updated.Invoke(this, new EventArgs());
 }
Beispiel #4
0
 /// <summary>
 /// Finds a specific book given its ID.
 /// </summary>
 /// <param name="id"></param>
 /// <returns>The book with the ID provided</returns>
 public Book Find(int id)
 {
     return(bookRepository.Find(id));
 }
Beispiel #5
0
        /// <summary>
        /// Method to edit a book
        /// </summary>
        /// <param name="item">book to edit</param>
        public void Edit(Book item)
        {
            var booktoedit = bookRepo.Find(item.Id);

            bookRepo.Edit(booktoedit);
        }
Beispiel #6
0
 public Book FindBook(int key)
 {
     return(bookRepository.Find(key));
 }