public async Task <BoxOfficeMojoMainServiceModel> GetMovieDataAsync(string movieTitleId) { string contentFilePath = GlobalConstants.MainContentBoxOfficeMojoLogFilePath; string mainContentUrl = string.Format(GlobalConstants.BoxOfficeMojoMainContentUrl, movieTitleId); HtmlNode docNode = await GetDocNode(contentFilePath, mainContentUrl); HtmlNode budgetNode = docNode .SelectSingleNode("//td[contains(text(), 'Production Budget:')]/b[normalize-space(text())]"); HtmlNode grossForeignNode = docNode .SelectSingleNode("//div[@class='mp_box_content']/*/tr[2]/td[2][normalize-space(text())]"); HtmlNode grossUsaNode = docNode .SelectSingleNode("//div[@class='mp_box_content']/*/tr[1]/td[2][normalize-space(text())]"); HtmlNode titleNode = docNode .SelectSingleNode("//font[@size='6']"); decimal budget = await Task.Run(() => this.GetBudget(budgetNode)); decimal grossForeign = await Task.Run(() => this.GetGross(grossForeignNode)); decimal grossUsa = await Task.Run(() => this.GetGross(grossUsaNode)); string title = string.Empty; if (titleNode != null) { title = titleNode.InnerText.Trim(); } var model = new BoxOfficeMojoMainServiceModel() { BoxOfficeMojoId = movieTitleId, BoxOfficeMojoTitle = title, Budget = budget, GrossForeign = grossForeign, GrossUsa = grossUsa }; return(model); }
public async Task<IActionResult> Search(MovieSearchTitleFormModel formSearchModel) { const string none = WebConstants.RadioButtonNoneValue; string blurayDotComTitleId = formSearchModel.BlurayDotComSelectedTitle; string boxOfficeMojoTitleId = formSearchModel.BoxOfficeMojoSelectedTitle; string dvdEmpireTiteId = formSearchModel.DvdEmpireSelectedTitle; string imdbTitleId = formSearchModel.ImdbSelectedTitle; string rottenTomatoesTitleId = formSearchModel.RottenTomattoesSelectedTitle; MovieFormMainModel formMainModel = new MovieFormMainModel(); #region Blu-ray.com if (!string.IsNullOrEmpty(blurayDotComTitleId) && blurayDotComTitleId != none) { //BlurayDotComMainServiceModel blurayDotComServiceModel // = await this.blurayDotComService.GetMovieDataAsync(blurayDotComTitleId); } #endregion Blu-ray.com #region Box Office Mojo if (!string.IsNullOrEmpty(boxOfficeMojoTitleId) && boxOfficeMojoTitleId != none) { try { BoxOfficeMojoMainServiceModel boxOfficeMojoServiceModel = await this.boxOfficeMojoService.GetMovieDataAsync(boxOfficeMojoTitleId); IMapper config = new MapperConfiguration(cfg => { cfg.CreateMap<BoxOfficeMojoMainServiceModel, MovieFormMainModel>(); }) .CreateMapper(); config.Map(boxOfficeMojoServiceModel, formMainModel); } catch (Exception ex) { await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } } #endregion Box Office Mojo #region IMDb if (!string.IsNullOrEmpty(imdbTitleId) && imdbTitleId != none) { try { ImdbMainServiceModel imdbServiceModel = await this.imdbService.GetMovieDataAsync(imdbTitleId); this.mapper.Map(imdbServiceModel, formMainModel); IEnumerable<string> colorNames = imdbServiceModel.Colors; formMainModel.SelectedColors = await this.movieDbService.GetColorsIdFromNameAsync(colorNames); IEnumerable<string> countryNames = imdbServiceModel.Countries; formMainModel.SelectedCountries = await this.movieDbService.GetCountriesIdFromNameAsync(countryNames); IEnumerable<string> genreNames = imdbServiceModel.Genres; formMainModel.SelectedGenres = await this.movieDbService.GetGenresIdFromNameAsync(genreNames); IEnumerable<string> languageNames = imdbServiceModel.Languages; formMainModel.SelectedLanguages = await this.movieDbService.GetLanguagesIdFromNameAsync(languageNames); } catch (Exception ex) { await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } } #endregion IMDb #region Rotten Tomattoes if (!string.IsNullOrEmpty(rottenTomatoesTitleId) && rottenTomatoesTitleId != none) { try { RottenTomatoesMainServiceModel rottenTomatoesServiceModel = await this.rottenTomatoesService.GetMovieDataAsync(rottenTomatoesTitleId); IMapper config = new MapperConfiguration(cfg => { cfg.CreateMap<RottenTomatoesMainServiceModel, MovieFormMainModel>(); }) .CreateMapper(); config.Map(rottenTomatoesServiceModel, formMainModel); } catch (Exception ex) { await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } } #endregion Rotten Tomattoes await this.PopulateFormMainModel(formMainModel); return View("Edit", formMainModel); }