コード例 #1
0
        public IHttpActionResult GetMovieDetails(int id)
        {
            var movie   = MovieRepository.FindSingle(id);
            var reviews = movieReviewRepository.GetAllByMovieID(id);

            if (movie == null)
            {
                return(NotFound());
            }
            else
            {
                // MAP Movie -> MovieDTO
                MovieDTO movieDTOReturn = new MovieDTO();
                AutoMapper.Mapper.Map(movie, movieDTOReturn);
                movieDTOReturn.Rating = reviews.Average(o => o.MovieRating);
                return(Ok(movieDTOReturn));
            }
        }
コード例 #2
0
        public IHttpActionResult GetAllByMovieID(int id)
        {
            var movieReviews = MOVIEREVIEWRepository.GetAllByMovieID(id);
            var people       = personRepository.GetAll();

            if (movieReviews == null || !movieReviews.Any())
            {
                return(NotFound());
            }
            else
            {
                // MAP moviereview -> moviereviewDTO
                List <MovieReviewDTO> MovieReviewDTO = new List <MovieReviewDTO>();
                AutoMapper.Mapper.Map(movieReviews, MovieReviewDTO);
                foreach (MovieReviewDTO m in MovieReviewDTO)
                {
                    m.ReviewerFirstName = people.Where(z => z.PersonID == m.Reviewer).FirstOrDefault().FirstName;
                    m.ReviewerLastName  = people.Where(z => z.PersonID == m.Reviewer).FirstOrDefault().LastName;
                }
                return(Ok(MovieReviewDTO));
            }
        }