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); }
public async Task<IActionResult> Search(string title) { if (title == null) { return BadRequest(); } MovieSearchTitleFormModel formModel = new MovieSearchTitleFormModel(); formModel.SearchTitleText = title; try { SearchTitleBaseServiceModel blurayDotComServiceModel = await this.blurayDotComService.SearchTitleResultsAsync(title); formModel.BlurayDoComSearchTitleResults = blurayDotComServiceModel.SearchTitleResults.AsNotNull(); } catch (Exception ex) { formModel.BoxOfficeMojoExceptionMessage = ex.Message; await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } try { SearchTitleBaseServiceModel boxOfficeMojoServiceModel = await this.boxOfficeMojoService.SearchTitleResultsAsync(title); formModel.BoxOfficeMojoSearchTitleResults = boxOfficeMojoServiceModel.SearchTitleResults.AsNotNull(); } catch (Exception ex) { formModel.BoxOfficeMojoExceptionMessage = ex.Message; await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } try { SearchTitleBaseServiceModel dvdEmpireServiceModel = await this.dvdEmpireService.SearchTitleResultsAsync(title); formModel.DvdEmpireSearchTitleResults = dvdEmpireServiceModel.SearchTitleResults.AsNotNull(); } catch (Exception ex) { formModel.DvdEmpireExceptionMessage = ex.Message; await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } try { SearchTitleBaseServiceModel imdbServiceModel = await this.imdbService.SearchTitleResultsAsync(title); formModel.ImdbSearchTitleResults = imdbServiceModel.SearchTitleResults.AsNotNull(); } catch (Exception ex) { formModel.ImdbExceptionMessage = ex.Message; await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } try { SearchTitleBaseServiceModel rottenTomatoesServiceModel = await this.rottenTomatoesService.SearchTitleResultsAsync(title); formModel.RottenTomatoesSearchTitleResults = rottenTomatoesServiceModel.SearchTitleResults.AsNotNull(); } catch (Exception ex) { formModel.RottentTomattoesExceptionMessage = ex.Message; await Task.Run(() => ex.Log(nameof(HomeController), nameof(Search))); } return View(formModel); }