Exemplo n.º 1
0
        public IEnumerable <BookListDTO> GetRecommendation(int userId)
        {
            if (_repo.getUserById(userId) == null)
            {
                throw new UserNotFoundException();
            }
            var books = _repo.GetBooksUserHasNotRead(userId);

            var result = new List <BookListDTO>();

            foreach (Book book in books)
            {
                var b = new BookListDTO
                {
                    BookId         = book.BookId,
                    Title          = book.Title,
                    AuthorFullName = book.AuthorFirst + " " + book.AuthorLast,
                    Rating         = (double)book.RatingSum / (double)book.TotalRatings
                };
                result.Add(b);
            }

            result.Sort((x, y) => y.Rating.CompareTo(x.Rating));

            return(result);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <ReplyData> > GetBooks()
        {
            try
            {
                var response = new ReplyData();
                var data     = await _context.Books.ToListAsync();

                response.data = _mapper.Map <List <Book>, List <BookListDTO> >(data);
                BookListDTO p = new BookListDTO();
                response.schema = new Schema(p, _context);
                return(response);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to load data"));
            }
        }
Exemplo n.º 3
0
        public IEnumerable <BookListDTO> GetBooksByLoanDate(DateTime loanDate)
        {
            var books  = _bookRepo.GetBooksByLoanDate(loanDate);
            var result = new List <BookListDTO>();

            foreach (Book book in books)
            {
                var b = new BookListDTO
                {
                    BookId         = book.BookId,
                    Title          = book.Title,
                    AuthorFullName = book.AuthorFirst + " " + book.AuthorLast,
                    Rating         = (double)book.RatingSum / (double)book.TotalRatings
                };
                result.Add(b);
            }
            return(result);
        }