Пример #1
0
        public async Task <MovieDetailsResponseModel> GetMovieAsync(int id)
        {
            var movie = await _movieRepository.GetByIdAsync(id);

            var casts = await _castRepository.GetCastByMovieId(id);

            var favoritecount = await _favoriteRepository.GetFavoriteCountAsync(id);

            var moviegenre = await _genreRepository.GetGenreByMovieId(id);


            var responseMovies = new MovieDetailsResponseModel
            {
                Id             = movie.Id,
                Title          = movie.Title,
                PosterUrl      = movie.PosterUrl,
                BackdropUrl    = movie.BackdropUrl,
                Rating         = movie.Rating,
                Overview       = movie.Overview,
                Tagline        = movie.Tagline,
                Budget         = movie.Budget,
                Revenue        = movie.Revenue,
                ImdbUrl        = movie.ImdbUrl,
                TmdbUrl        = movie.TmdbUrl,
                ReleaseDate    = movie.ReleaseDate,
                RunTime        = movie.RunTime,
                Price          = movie.Price,
                FavoritesCount = favoritecount,
                Casts          = new List <CastResponseModel>(),
                Genres         = moviegenre.ToList(),
            };

            foreach (var cast in casts)
            {
                var moviecast = await _castRepository.GetMovieCastById(cast.Id, id);

                responseMovies.Casts.Add(new MovieDetailsResponseModel.CastResponseModel
                {
                    Id          = cast.Id,
                    Name        = cast.Name,
                    Gender      = cast.Gender,
                    TmdbUrl     = cast.TmdbUrl,
                    ProfilePath = cast.ProfilePath,
                    Character   = moviecast.Character
                });
            }
            return(responseMovies);
        }