コード例 #1
0
ファイル: Home.aspx.cs プロジェクト: ojensen/WhatsOnInstant
    private List<MovieModel> SaveMoviesToDB(IList<dynamic> movies)
    {
        List<MovieModel> netflixMovies = new List<MovieModel>();
        if (movies != null)
        {

            MoviesDBDataContext db = new MoviesDBDataContext();
            foreach (var movie in movies)
            {
                string id = movie.Id;
                NetflixMovy movieFromDb = (from m in db.NetflixMovies
                                           where m.NetflixID == id
                                           select m).FirstOrDefault();
                if (movieFromDb == null)//If not already in db add it
                {
                    MovieModel nm = new MovieModel(movie);

                    db.NetflixMovies.InsertOnSubmit(nm.Netflix);
                    movieFromDb = nm.Netflix;
                }
                MovieModel mm = new MovieModel(movieFromDb, null);
                netflixMovies.Add(mm);
            }
            db.SubmitChanges();
        }
        return netflixMovies;
    }
コード例 #2
0
ファイル: Home.aspx.cs プロジェクト: ojensen/WhatsOnInstant
    private List<MovieModel> SetupRottenTomatoRatings(List<MovieModel> movies)
    {
        List<MovieModel> movieData = new List<MovieModel>();
        MoviesDBDataContext db = new MoviesDBDataContext();
        foreach (var m in movies)
        {
            RtMovy rtMovie = null;
            if (m.Netflix.Type == "Movie")//type = movie
            {
                int id = m.Netflix.MovieID;
                rtMovie = (from movie in db.RtMovies
                           where movie.MovieID == id
                           select movie).FirstOrDefault();
                if (rtMovie == null)
                {
                    Movie rt = RottenTomatoes.SearchMoviesByTitle(m.Netflix.Title, m.Netflix.ReleaseYear.ToString());
                    if (rt != null)
                    {
                        rtMovie = new RtMovy();
                        rtMovie.MovieID = m.Netflix.MovieID;

                        var a = rt.Ratings.Where(r => r.Type == "audience_rating").FirstOrDefault();
                        var b = rt.Ratings.Where(r => r.Type == "audience_score").FirstOrDefault();
                        var c = rt.Ratings.Where(r => r.Type == "critics_rating").FirstOrDefault();
                        var d = rt.Ratings.Where(r => r.Type == "critics_score").FirstOrDefault();
                        var e = rt.Links.Where(r => r.Type == "alternate").FirstOrDefault();

                        if (a != null)
                            rtMovie.AudienceRating = a.Score;
                        else
                            rtMovie.AudienceRating = "Unknown";
                        if (b != null)
                            rtMovie.AudienceScore = b.Score;
                        if (c != null)
                            rtMovie.CriticsRating = c.Score;
                        else
                            rtMovie.CriticsRating = "Unknown";
                        if (d != null)
                            rtMovie.CriticsScore = d.Score;
                        if (e != null)
                            rtMovie.WebsiteLink = e.Url;

                        if (rtMovie.CriticsRating != null)
                            rtMovie.CriticsRating = rtMovie.CriticsRating.Replace("\"", "").ToLower();
                        if (rtMovie.AudienceRating != null)
                            rtMovie.AudienceRating = rtMovie.AudienceRating.Replace("\"", "").ToLower();

                        if (rtMovie.CriticsScore == "-1")
                        {
                            rtMovie.CriticsScore = rtMovie.AudienceScore;
                            rtMovie.CriticsRating = "popcorn";
                        }

                        db.RtMovies.InsertOnSubmit(rtMovie);

                    }
                    else
                    {
                        rtMovie = new RtMovy();
                        rtMovie.WebsiteLink = string.Empty;
                        rtMovie.AudienceRating = "";
                        rtMovie.AudienceScore = "0";
                        rtMovie.CriticsScore = "0";
                        rtMovie.CriticsRating = "";
                        rtMovie.MovieID = m.Netflix.MovieID;
                        db.RtMovies.InsertOnSubmit(rtMovie);
                    }

                }

            }
            else
            {
                rtMovie = new RtMovy();
                rtMovie.WebsiteLink = string.Empty;
                rtMovie.AudienceRating = "";
                rtMovie.AudienceScore = "0";
                rtMovie.CriticsScore = "0";
                rtMovie.CriticsRating = "";
            }
            movieData.Add( new MovieModel( m.Netflix, rtMovie));
          //  movieData.Add(new MovieModel(m.NetflixID, m.Title, m.ReleaseYear, m.Rating, m.Synopsis, m.ShortSynopsis, m.AverageRating, m.LargeUrl, m.Runtime, rtMovie.AudienceScore, rtMovie.WebsiteLink, rtMovie.CriticsScore, rtMovie.AudienceRating, rtMovie.CriticsRating, m.ExpiresDate, m.ApiId.Value));
        }
        db.SubmitChanges();

        return movieData;
    }