/// <summary>
        /// Returns the list of overdue books
        /// </summary>
        /// <returns>List of overdue books</returns>
        public IEnumerable <Book> GetOverdueBooks()
        {
            try
            {
                var books   = _booksRepository.GetAll();
                var overdue = _borrowDetailsRepository.GetAll().Where(x => x.DueDate < DateTime.Today);

                IEnumerable <Book> overdueBooks = (from book in books
                                                   join overdueBook in overdue
                                                   on book.Id equals overdueBook.BookId
                                                   select new Book()
                {
                    Id = book.Id, Name = book.Name
                });

                return(overdueBooks);
            }
            catch (NullReferenceException)
            {
                return(new List <Book>());
            }
            catch (ArgumentNullException)
            {
                return(new List <Book>());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Assigns a book
        /// </summary>
        /// <param name="studentId">student Id</param>
        /// <param name="bookId">book Id</param>
        /// <returns>Returns true if borrowing was successful, else false</returns>
        public bool AssignBook(int studentId, int bookId)
        {
            var borrowedBook = _booksRepository.Find(bookId);

            if (borrowedBook == null)
            {
                return(false);
            }

            IList <AssignDetails> borrorDetails = _borrowDetailsRepository.GetAll() as IList <AssignDetails>;

            borrorDetails.Add(new AssignDetails()
            {
                Id        = borrorDetails.Count + 1,
                BookId    = bookId,
                StudentId = studentId,
                DueDate   = DateTime.Today.AddDays(AssignDetailsRepository.NoOfDaysBookToBeAssigned)
            });

            return(true);
        }