Пример #1
0
        public IEnumerable <BookListDTO> GetBooks()
        {
            var books  = _bookRepo.GetBooks();
            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);
        }
Пример #2
0
        public IEnumerable <Models.DTOModels.BookReviewsDTO> GetAllBookReviewsForAllBooks()
        {
            var allReviews = _repo.GetAllReviews();
            var allBooks   = _bookRepo.GetBooks();
            var result     = new List <Models.DTOModels.BookReviewsDTO>();

            foreach (Book book in allBooks)
            {
                var reviews = new List <BookReviewDTO>();
                foreach (BookReview review in allReviews)
                {
                    if (review.BookId == book.BookId)
                    {
                        var user = _userRepo.getUserById(review.UserId);
                        reviews.Add(new BookReviewDTO
                        {
                            BookReviewId = review.BookReviewId,
                            UserId       = user.UserId,
                            UserName     = user.FirstName + " " + user.LastName,
                            Rating       = review.Rating,
                            Review       = review.Review
                        });
                    }
                }
                var b = new Models.DTOModels.BookReviewsDTO
                {
                    BookId    = book.BookId,
                    BookTitle = book.Title,
                    Reviews   = reviews
                };

                if (reviews.Count >= 1)
                {
                    result.Add(b);
                }
            }
            return(result);
        }