コード例 #1
0
        /// <summary>
        /// Gets the movie information.
        /// </summary>
        /// <param name="imbdId">The imbd identifier.</param>
        public MovieFullInfo GetMovieInfo(string imbdId)
        {
            // gets movie info from db
            var             dbInstance  = new DbManager();
            DbMovieFullInfo movieFromDb = dbInstance.GetMovieByImdbId(imbdId);
            MovieFullInfo   movie       = MapFullMovieDbEntitieToBl(movieFromDb);

            if (movie != null)
            {
                return(movie);
            }

            // gets movie info from api
            var service = new MovieBoxApiService();
            ApiMovieFullInfo movieFromApi = service.GetMovie(imbdId);

            if (movieFromApi != null)
            {
                DbMovieFullInfo dbMoveEntity = MapApiFullInfoMovieToDb(movieFromApi);

                // add movie to db
                dbInstance.AddMovie(dbMoveEntity);
                MovieFullInfo movieBl = MapFullMovieDbEntitieToBl(dbMoveEntity);

                return(movieBl);
            }

            return(new MovieFullInfo());
        }
コード例 #2
0
        /// <summary>
        /// Maps the full info movie entities
        /// from db model to Bl model.
        /// </summary>
        /// <param name="movie">The movie.</param>
        private MovieFullInfo MapFullMovieDbEntitieToBl(DbMovieFullInfo movie)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <DbMovieFullInfo, MovieFullInfo>();
                cfg.CreateMap <DbRating, MovieRating>();
            });

            config.AssertConfigurationIsValid();

            IMapper       iMapper     = config.CreateMapper();
            MovieFullInfo destination = iMapper.Map <DbMovieFullInfo, MovieFullInfo>(movie);

            return(destination);
        }
コード例 #3
0
ファイル: MovieController.cs プロジェクト: pnedov/NetCore
        public IActionResult Index(string imdbIdParam)
        {
            if (string.IsNullOrEmpty(imdbIdParam))
            {
                return(View(null));
            }

            var           moviesInstance = new BLManager();
            MovieFullInfo movie          = moviesInstance.GetMovieInfo(imdbIdParam);

            string imdbUrl = HelperMethods.GetAppConfigValue("imdbUrl");

            ViewBag.ImDbUrl = imdbUrl += movie.ImdbID;

            return(View(movie));
        }