Пример #1
0
        public IEnumerable <MovieDTO> GetAllMovies()
        {
            var movies     = _moviesRepository.GetAllMovies().ToList();
            var allReviews = _reviewsRepository.GetAll();

            foreach (var item in movies)
            {
                int rate = 0;
                var currentMovieReviews = allReviews.Where(x => x.ContentType == ReviewContentType.Movie && x.FilmId == item.Id).ToList();
                if (currentMovieReviews.Count() != 0)
                {
                    var currentMovieReviewsCount = currentMovieReviews.Count();
                    foreach (var review in currentMovieReviews)
                    {
                        rate += (int)((review.ActorsRating + review.DirectingRating + review.PlotRating + review.SpectacleRating) / 4);
                    }
                    item.Rate = (int)(rate / currentMovieReviews.Count());
                }
            }
            return(_mapper.Map <IEnumerable <Movie>, IEnumerable <MovieDTO> > (movies.ToList()));
        }
Пример #2
0
        public List <SerialDTO> GetSerials()
        {
            var serials    = _serialRepository.GetAllSerials();
            var allReviews = _reviewsRepository.GetAll();

            foreach (var item in serials)
            {
                int rate = 0;
                var currentSerialReviews = allReviews.Where(x => x.ContentType == ReviewContentType.Serial && x.FilmId == item.Id).ToList();
                if (currentSerialReviews.Count() != 0)
                {
                    var currentMovieReviewsCount = currentSerialReviews.Count();
                    foreach (var review in currentSerialReviews)
                    {
                        rate += (int)((review.ActorsRating + review.DirectingRating + review.PlotRating + review.SpectacleRating) / 4);
                    }
                    item.Rating = rate / currentMovieReviewsCount;
                }
            }
            return(_mapper.Map <List <SerialDTO> >(serials.ToList()));
        }
Пример #3
0
 public IActionResult GetAll()
 {
     return(Ok(_reviewsRepository.GetAll()));
 }