public IEnumerable <ReturnBookDTO> GetBorrowedBooks() { List <ReturnBookDTO> returnBookDTOs = new List <ReturnBookDTO>(); var bookCopies = _BookCopyService.GetBorrowedBooks(); foreach (var bookCopy in bookCopies) { var bookInfo = _BookInfoService.BookInfoOf(bookCopy); var lastTrans = _BookTransactionInfoRepository.GetLastBookTransaction(bookCopy.Id); //If no borrow transaction was found, then its a possible error. if (lastTrans != null) { var requiredFee = ComputeNecessaryFee(bookCopy, lastTrans); var user = _LibraryUserService.FindById(lastTrans.LibraryUserId); var newReturnBookDTO = new ReturnBookDTO(); newReturnBookDTO.LibraryUser = user; newReturnBookDTO.BookInfo = bookInfo; newReturnBookDTO.RequiredFee = requiredFee; newReturnBookDTO.BookCopy = bookCopy; if (user.LibraryUserType == LibraryUser.UserType.Student) { newReturnBookDTO.TransactionInfo = new JustReturnBookTransaction(bookCopy, lastTrans); } else if (user.LibraryUserType == LibraryUser.UserType.Instructor || user.LibraryUserType == LibraryUser.UserType.Employee) { newReturnBookDTO.TransactionInfo = new ReturnBookIgnorePaymentTransaction(bookCopy, lastTrans); } returnBookDTOs.Add(newReturnBookDTO); } else { Debug.WriteLine("Possible error. A book was borrowed but no transaction info was found."); } } return(returnBookDTOs); }