Beispiel #1
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);
        }
Beispiel #2
0
 public IActionResult GetAll()
 {
     return(Ok(_reviewsRepository.GetAllReviews()));
 }
Beispiel #3
0
        public int?getReviewPage(int UserId, int PageNumber, int PageSize, ReviewSortState sortState, string titleName)
        {
            if (titleName == null)
            {
                return(null);
            }
            var reviewsList = _mapper.Map <IEnumerable <Review>, IEnumerable <ReviewDTO> >(_reviewsRepository.GetAllReviews(UserId));

            reviewsList = sortQuery(reviewsList, sortState);
            var foundElement = reviewsList.FirstOrDefault(s => s.ReviewTitle.Contains(titleName));

            if (foundElement == null)
            {
                return(null);
            }
            int index = reviewsList.IndexOf(foundElement) + 1;

            if (index <= PageSize)
            {
                return(1);
            }
            var remaining = ((double)index / (double)PageSize);

            return((int)Math.Round(remaining, 0, MidpointRounding.AwayFromZero));
        }