public MoviesListModel GetMovieByName(string name, int currentUserId) { MoviesListModel list = new MoviesListModel(); if (!String.IsNullOrEmpty(name)) { try { HttpClient httpClient = new HttpClient(); string body = httpClient.GetStringAsync(APIQueries.SearchByName_Query(name)).Result; list = JsonConvert.DeserializeObject <MoviesListModel>(body); } catch (Exception ex) { AppErrorRepo.InsertError(ex); } //List<TM_Movie> p = ProfileBLL.GetUserWatchedMovies(currentUserId); //foreach (TM_Movie wl in p) //Watched List // foreach (var rl in s.Results) //ResultList // if (wl.Id == rl.Id || wl.ImdbId == rl.Id.ToString()) // rl.UserDataAboutMovie.IsWatched = true; } return(list); }
public ActionResult Index() { var movies = _context.movies.ToList(); var movieListView = new MoviesListModel() { Movies = movies }; return(View(movieListView)); }
// Returns scraped movie data public async Task <IEnumerable <MovieModel> > GetMovies() { string url = "https://www.imdb.com/chart/top?ref_=nb_mv_3_chttp"; string html = await SpiderModel.HttpGet(url); if (html != null) { HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var Images = htmlDoc.DocumentNode.SelectNodes("//td[@class='posterColumn']//img"); var Titles = htmlDoc.DocumentNode.SelectNodes("//td[@class='titleColumn']//a"); var Years = htmlDoc.DocumentNode.SelectNodes("//span[@class='secondaryInfo']"); if (Years != null) { List <MovieModel> movieList = new List <MovieModel>(); for (int z = 0; z < Years.Count; z++) { MovieModel movie = new MovieModel(); HtmlAttribute src = Images[z].Attributes[@"src"]; string[] split = src.Value.Split('@'); movie.Image = split.Length == 3 ? (split[0] + "@@._V1_UY368_CR3,0,240,360_AL_.jpg") : (split[0] + "@._V1_UY368_CR3,0,240,360_AL_.jpg"); movie.Title = Titles[z].InnerText; movie.Year = Years[z].InnerText.Substring(1, 4); movieList.Add(movie); } MoviesListModel.SetMoviesData(movieList); return(MoviesListModel.GetMoviesData()); } else { return(null); } } else { return(null); } }
public MoviesListModel GetTrendings() { MoviesListModel list = new MoviesListModel(); try { HttpClient httpClient = new HttpClient(); string body = httpClient.GetStringAsync(APIQueries.DiscoverByPopularity_Query()).Result; list = JsonConvert.DeserializeObject <MoviesListModel>(body); } catch (Exception ex) { AppErrorRepo.InsertError(ex); } //List<TM_Movie> p = ProfileBLL.GetUserWatchedMovies(currentUserId); //foreach (TM_Movie wl in p) //Watched List // foreach (var rl in s.Results) //ResultList // if (wl.Id == rl.Id || wl.ImdbId == rl.Id.ToString()) // rl.UserDataAboutMovie.IsWatched = true; return(list); }
private async Task <List <MoviesListModel> > GetMoviesListModel(HttpServiceResult <BaseMoviesResult> baseMoviesResult, string language) { var model = new List <MoviesListModel>(); if (!baseMoviesResult.IsSucess) { return(model); } List <BaseMoviesListResult> movies = new List <BaseMoviesListResult>(); if (baseMoviesResult.Result != null && baseMoviesResult.Result.Results != null) { movies = baseMoviesResult.Result.Results; } foreach (var movie in movies) { var movieModel = new MoviesListModel() { Title = movie.Title, BackdropPath = movie.BackdropPath, VoteAverage = movie.VoteAverage, Id = movie.Id, Overview = movie.Overview, PosterPath = movie.PosterPath }; if (movie.ReleaseDate != null) { if (DateTime.TryParse(movie.ReleaseDate, out DateTime releaseDate)) { movieModel.ReleaseDate = releaseDate; } } if (movie.GenreIds != null) { foreach (var genreId in movie.GenreIds) { var genreResult = await genresService.GetGenreById(genreId, language); if (genreResult == null) { continue; } movieModel.Genres.Add(new Models.Genres.GenreModel() { Name = genreResult.Name != null ? genreResult.Name : string.Empty, Id = genreResult.Id }); } } model.Add(movieModel); } return(model); }