Beispiel #1
0
        public List <BookDTO> FindBooks(BookFindCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }

            var            books  = _bookRepository.FindByCriteria(criteria);
            List <BookDTO> result = new List <BookDTO>();
            BookDTO        recDTO;

            foreach (var book in books)
            {
                recDTO = BookMapper.Map(book);

                if (criteria.IncludeIsAvaliable)
                {
                    recDTO.IsAvaliable = _borrowRepository.isBookAvaliable(recDTO.BookID);
                }

                if (criteria.IsOverdue.HasValue)
                {
                    if (criteria.IsOverdue.Value == true && _borrowRepository.isBookOverdue(recDTO.BookID))
                    {
                        result.Add(recDTO);
                    }
                    else if (criteria.IsOverdue.Value == false && !_borrowRepository.isBookOverdue(recDTO.BookID))
                    {
                        result.Add(recDTO);
                    }
                }
                else
                {
                    result.Add(recDTO);
                }
            }

            return(result);
        }