public override List<ListMovie> ParseListMovieResponse(string response) { XDocument doc = (System.Xml.Linq.XDocument)ToResponse(response); var dataElement = doc.GetXElement("data"); if (dataElement == null || dataElement.Descendants().Count() == 0) return new List<ListMovie>(); var xmovies = dataElement.GetXElements("movie").ToList(); List<ListMovie> movies = new List<ListMovie>(); foreach (XElement xmovie in xmovies) { ListMovie movie = new ListMovie(); FillAbstractYifyMovie(xmovie, movie); movie.State = xmovie.Descendants("state").First().GetXElementValue<string>(); MovieImage image; image = new MovieImage() { Url = xmovie.Descendants("small_cover_image").First().GetXElementValue<string>(), ImageSize = ImageSize.Small, ImageType = MovieImageType.Cover }; movie.Images.Add(image); image = new MovieImage() { Url = xmovie.Descendants("medium_cover_image").First().GetXElementValue<string>(), ImageSize = ImageSize.Medium, ImageType = MovieImageType.Cover }; movie.Images.Add(image); movies.Add(movie); } return movies; }
public ActionResult Details(int id) { var movies = new List <Movie> { new Movie() { Name = "Movie 1" }, new Movie() { Name = "Movie 2" }, }; var viewModel = new ListMovie() { Movies = movies }; return(View(viewModel)); }
public static List <ListMovie> ParseListMovieResponse(string response) { XDocument doc = LoadXDoc(response); var xmovies = doc.GetXElement("data").GetXElements("movie").ToList(); List <ListMovie> movies = new List <ListMovie>(); foreach (XElement xmovie in xmovies) { ListMovie movie = new ListMovie(); FillAbstractYifyMovie(xmovie, movie); movie.State = xmovie.Descendants("state").First().GetXElementValue <string>(); MovieImage image; image = new MovieImage() { Url = xmovie.Descendants("small_cover_image").First().GetXElementValue <string>(), ImageSize = ImageSize.Small, ImageType = MovieImageType.Cover }; movie.Images.Add(image); image = new MovieImage() { Url = xmovie.Descendants("medium_cover_image").First().GetXElementValue <string>(), ImageSize = ImageSize.Medium, ImageType = MovieImageType.Cover }; movie.Images.Add(image); movies.Add(movie); } return(movies); }
public override List <Data.ListMovie> ParseListMovieResponse(string response) { var jsonDoc = (JObject)ToResponse(response); var count = jsonDoc["data"]["movie_count"].Value <int>(); List <JToken> moviesJtkn; if (count == 0) { return(new List <ListMovie>()); } else { moviesJtkn = jsonDoc["data"]["movies"].ToList(); } List <ListMovie> movies = new List <ListMovie>(); foreach (JToken xmovie in moviesJtkn) { ListMovie movie = new ListMovie(); FillAbstractYifyMovie(xmovie, movie); movie.State = xmovie["state"].Value <string>(); MovieImage image; try { image = new MovieImage() { Url = xmovie["small_cover_image"].Value <string>(), ImageSize = ImageSize.Small, ImageType = MovieImageType.Cover }; movie.Images.Add(image); } catch (Exception) { } try { image = new MovieImage() { Url = xmovie["medium_cover_image"].Value <string>(), ImageSize = ImageSize.Medium, ImageType = MovieImageType.Cover }; movie.Images.Add(image); } catch (Exception) { } try { image = new MovieImage() { Url = xmovie["large_cover_image"].Value <string>(), ImageSize = ImageSize.Large, ImageType = MovieImageType.Cover }; movie.Images.Add(image); } catch (Exception) { } try { image = new MovieImage() { Url = xmovie["background_image"].Value <string>(), ImageSize = ImageSize.NotRelevent, ImageType = MovieImageType.Background }; movie.Images.Add(image); } catch (Exception) { } try { image = new MovieImage() { Url = xmovie["background_image_original"].Value <string>(), ImageSize = ImageSize.NotRelevent, ImageType = MovieImageType.Background }; movie.Images.Add(image); } catch (Exception) { } movies.Add(movie); } return(movies); }