コード例 #1
0
        [HttpPost] ///add title to list
        public JsonResult Add(String movieid, String listid, String formats)
        {
            formats = formats.Trim().Replace(" ", ", ").Replace("-", "");
            FilmTroveContext ftc  = (FilmTroveContext)HttpContext.Items["ftcontext"];
            UserProfile      up   = ftc.UserProfiles.Include("UserLists.Items").Where(u => u.UserId == WebSecurity.CurrentUserId).Single();
            Int32            lid  = Convert.ToInt32(listid);
            Int32            mid  = Convert.ToInt32(movieid);
            UserList         list = up.UserLists.Where(l => l.ListId == lid).Single();

            //UserList list = ftc.Lists.Where(l => l.ListId == lid && l.Owner == up).Single();
            if (list.Items.Any(i => i.MovieId == mid))
            {
                return(Json(new { Success = false, Message = "Err. The list already contains that title." }));
            }
            Movie        movie = ftc.Movies.Find(Convert.ToInt32(movieid));
            UserListItem uli   = ftc.ListItems.Create();

            uli.List         = list;
            uli.Movie        = movie;
            uli.MovieId      = movie.MovieId;
            uli.MovieTitle   = movie.Title;
            uli.OwnedFormats = (Format)Enum.Parse(typeof(Format), formats);

            ftc.ListItems.Add(uli);
            ftc.SaveChanges();

            return(Json(new { Success = true }));
        }
コード例 #2
0
        public ActionResult Details(String id, String name)
        {
            FilmTroveContext ftc      = (FilmTroveContext)HttpContext.Items["ftcontext"];
            Int32            personid = Int32.Parse(id);

            FilmTrove.Models.Person p = ftc.People.Include("Roles.Movie").Where(person => person.PersonId == personid).Single();
            //PersonDisplay p = ftc.Database.SqlQuery<PersonDisplay>("");
            if (p.DateLastModified > DateTime.Now.AddDays(14))
            {
                p.Netflix.NeedsUpdate = true;
            }

            if (p.RottenTomatoes.NeedsUpdate)
            {
            }
            if (p.Imdb.NeedsUpdate)
            {
            }

            ftc.SaveChanges();
            ViewBag.Person          = p;
            ViewBag.NeedFilmography = p.Roles.Count < 1 | p.Netflix.NeedsUpdate;

            return(View());
        }
コード例 #3
0
 public ActionResult Links(String id, String title)
 {
     if (WebSecurity.IsAuthenticated)
     {
         Int32 movieid = Convert.ToInt32(id);
         ViewBag.Id = id;
         FilmTroveContext ftc   = (FilmTroveContext)HttpContext.Items["ftcontext"];
         Movie            movie = ftc.Movies.Find(movieid);
         UserProfile      up    = ftc.UserProfiles.Include("UserLists.Items").Where(u => u.UserId == WebSecurity.CurrentUserId).Single();
         if (up.UserLists.Count < 1)
         {
             ///this is only temporary
             ftc.Lists.Add(new UserList()
             {
                 Owner = up, ListName = "My Collection"
             });
             ftc.SaveChanges();
         }
         ViewBag.Lists = up.UserLists.Select(l =>
                                             new ListInfo {
             ListId   = l.ListId,
             ListName = l.ListName,
             InList   = l.Items.Any(i => i.MovieId == movie.MovieId)
         }).ToList();
     }
     else
     {
         ViewBag.Id            = id;
         ViewBag.FriendlyTitle = "Please log in to add titles to your lists.";
     }
     return(View());
 }
コード例 #4
0
ファイル: Global.asax.cs プロジェクト: donomans/FilmTrove
        protected void Application_EndRequest(object sender, EventArgs e)
        {
            FilmTroveContext ftc = (FilmTroveContext)HttpContext.Current.Items["ftcontext"];

            ftc.Dispose();
            //throw new Exception();
        }
コード例 #5
0
        [HttpPost]///new list
        public JsonResult New(String listname, String movieid)
        {
            Int32 listid = -1;

            if (WebSecurity.IsAuthenticated)
            {
                FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];
                UserProfile      up  = ftc.UserProfiles.Find(WebSecurity.CurrentUserId);
                if (up.UserLists.Where(l => l.ListName == listname).Count() < 1)
                {
                    UserList ul = ftc.Lists.Add(new UserList()
                    {
                        ListName = listname,
                        Owner    = up
                    });
                    ftc.SaveChanges();
                    //UserList ul = ftc.Lists.Where(l => l.ListName == listname).Single();
                    listid = ul.ListId;
                }
                else
                {
                    return(this.Json(data: new { Success = false, Message = "You already have a list named \"" + listname + "\"" }));
                }
            }
            else
            {
            }
            return(this.Json(data: new { Success = true, ListId = listid, ListName = listname, MovieId = movieid }));
        }
コード例 #6
0
        public ActionResult Index()
        {
            FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];

            ViewBag.Movies = (from m in ftc.Movies
                              select m).Take(50);
            return(View());
        }
コード例 #7
0
        public ActionResult LoginCallBack()
        {
            AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("LoginCallBack"));

            if (result.IsSuccessful)
            {
                if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: true))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
                    ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;

                    FilmTroveContext ftc  = (FilmTroveContext)HttpContext.Items["ftcontext"];
                    UserProfile      user = ftc.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == result.ProviderUserId.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        UserProfile prof = new UserProfile()
                        {
                            UserName = result.ProviderUserId, Provider = result.Provider, NetflixAccount = new NetflixAccount()
                        };
                        if (result.UserName.Contains("@"))
                        {
                            prof.Email = result.UserName;
                        }
                        else
                        {
                            prof.Name = result.UserName;
                        }

                        UserProfile up = ftc.UserProfiles.Add(prof);
                        ftc.Lists.Add(new UserList()
                        {
                            ListName = "My Collection", Owner = up
                        });
                        ftc.SaveChanges();

                        String provider;
                        String providerUserId;

                        OAuthWebSecurity.TryDeserializeProviderUserId(loginData, out provider, out providerUserId);
                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, result.ProviderUserId);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);
                    }
                    else
                    {
                        //need to handle some error
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #8
0
ファイル: GeneralHelpers.cs プロジェクト: donomans/FilmTrove
        public static List <Models.Person> GetDatabasePeople(People results)
        {
            var netflixids = results.Select(p => p.Id);

            using (FilmTroveContext ftc = new FilmTroveContext())
            {
                ///1) find the matching records from the database
                var matchedpeople = ftc.People.Where(m => netflixids.Contains(m.Netflix.Id));
                ///2) find the records that don't have a match
                ///select the ids and get the netflix Ids that aren't in the FT database
                var ftnfids             = matchedpeople.Select(m => m.Netflix.Id);
                var netflixidsunmatched = netflixids.Where(m => !ftnfids.Contains(m));
                //Int32 count = 0;
                foreach (String nid in netflixidsunmatched)
                {
                    ///create FT database records for each of these with the movies basic information for now
                    FilmTrove.Models.Person  newperson     = ftc.People.Create();
                    FlixSharp.Holders.Person netflixperson = results.Find(nid);
                    FillBasicPerson(newperson, netflixperson);
                    //newperson.Name = netflixperson.Name;
                    //newperson.Bio = netflixperson.Bio;
                    //newperson.Netflix = new NetflixPersonInfo();
                    //newperson.Netflix.Id = netflixperson.Id;
                    //newperson.Netflix.IdUrl = netflixperson.IdUrl;
                    //newperson.Netflix.Url = netflixperson.NetflixSiteUrl;

                    ftc.People.Add(newperson);
                }

                try
                {
                    //count =
                    ftc.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                    ///need to add some sort of logging?
                }
                //if (count > 0)
                if (matchedpeople.Count() < results.Count())
                {
                    matchedpeople = ftc.People.Where(m => netflixids.Contains(m.Netflix.Id));
                }
                //else
                //    return matchedpeople.ToList();

                return(results.Select(p =>
                                      matchedpeople.First(f =>
                                                          f.Netflix.Id == p.Id)).ToList());
            }
        }
コード例 #9
0
        public ActionResult Me(UserUpdate changes)
        {
            ///update the data and return to previous url or something?
            FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];
            UserProfile      up  = ftc.UserProfiles.Find(WebSecurity.CurrentUserId);

            up.Name  = changes.Name;
            up.Email = changes.Email;

            ftc.SaveChanges();

            return(View("Me", changes));
        }
コード例 #10
0
        public ActionResult NetflixUnlink()
        {
            FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];

            UserProfile up = ftc.UserProfiles.Find(WebSecurity.CurrentUserId);

            up.NetflixAccount.Token       = "";
            up.NetflixAccount.TokenSecret = "";
            up.NetflixAccount.UserId      = "";
            Int32 changed = ftc.SaveChanges();

            UserUpdate userupdate = new UserUpdate(up);

            ViewBag.NetflixLinked = null;
            return(View("Me", userupdate));
        }
コード例 #11
0
        public ActionResult Me()
        {
            if (WebSecurity.IsAuthenticated)
            {
                FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];
                UserProfile      up  = ftc.UserProfiles.Find(WebSecurity.CurrentUserId);
                if (up.NetflixAccount.UserId != null && up.NetflixAccount.UserId != "")
                {
                    ViewBag.NetflixLinked = true;
                }
                UserUpdate userupdate = new UserUpdate(up);

                return(View(userupdate));
            }
            return(View());
        }
コード例 #12
0
        //
        // GET: /Lists/

        public ActionResult Collection()
        {
            if (WebSecurity.IsAuthenticated)
            {
                FilmTroveContext ftc  = (FilmTroveContext)HttpContext.Items["ftcontext"];
                UserProfile      prof = ftc.UserProfiles.Find(WebSecurity.CurrentUserId);
                if (prof.UserLists.Count < 1)//.Collection == null)
                {
                    UserList collection = new UserList();
                    collection.ListName = "My Collection";
                    collection.Owner    = prof;
                    //collection.Items = new HashSet<UserListItem>();
                    //prof.UserLists = new List<UserList>() { collection };
                    ftc.Lists.Add(collection);
                }
                ftc.SaveChanges();
            }
            return(View());
        }
コード例 #13
0
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer <FilmTroveContext>(null);

                try
                {
                    using (var context = new FilmTroveContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
コード例 #14
0
        public async Task <ActionResult> Details(String id, String title)
        {
            FilmTroveContext ftc     = (FilmTroveContext)HttpContext.Items["ftcontext"];
            Int32            movieid = Int32.Parse(id);

            FilmTrove.Models.Movie m = ftc.Movies.Include("Roles.Person").Where(movie => movie.MovieId == movieid).Single();

            Task <FlixSharp.Holders.Title> nfm = null;

            if (m.Netflix.NeedsUpdate)
            {
                nfm = Netflix.Fill.Titles.GetCompleteTitle(m.Netflix.IdUrl, true);//Randomized().
            }
            if (m.Amazon.NeedsUpdate || (m.Amazon.LastPriceUpdate.HasValue && ((m.Amazon.LastPriceUpdate.Value - DateTime.Now) > new TimeSpan(1, 0, 0, 0))))
            {
                if (m.Amazon.Id == null || m.Amazon.Id == "" ||
                    m.Amazon.LastFullUpdate.HasValue && ((m.Amazon.LastFullUpdate.Value - DateTime.Now) > new TimeSpan(7, 0, 0, 0)))
                {
                    ///1) do query to match up title and fill in id with priority to blu-ray
                }
                ///1) else use Id

                ///2) fill in found id
                ///3) purchase url (prioritize blu-ray)
                ///4) price
                ///5) update lastpriceupdate
            }
            if (m.Imdb.NeedsUpdate)
            {
                ///nothing
            }
            if (m.RottenTomatoes.NeedsUpdate ||
                (m.RottenTomatoes.LastFullUpdate.HasValue && ((m.Amazon.LastFullUpdate.Value - DateTime.Now) > new TimeSpan(7, 0, 0, 0))))
            {
                if (m.RottenTomatoes.Id == null || m.RottenTomatoes.Id == "" ||
                    m.RottenTomatoes.LastFullUpdate.HasValue && ((m.RottenTomatoes.LastFullUpdate.Value - DateTime.Now) > new TimeSpan(7, 0, 0, 0)))
                {
                    ///1) title match like with amazon or use Id if present
                }
                ///1.5) loop through the cast and match them with the current cast to get the role name filled.
                ///2) Critic score
                ///3) critic consensus
                ///4) poster medium
                ///5) poster large
                ///6) theatrical release
                ///7) dvd release
                ///8) average rating
                ///9) studio
                ///10) synopsis
            }
            #region Fill Netflix
            if (nfm != null)
            {
                var netflixtitle = await nfm;

                ///populate all the netflix information
                m.Netflix.NeedsUpdate = false;
                m.Netflix.AvgRating   = netflixtitle.AverageRating;
                m.Netflix.Awards      = netflixtitle.Awards.Select(a =>
                                                                   a.AwardName + ";#" + a.PersonIdUrl + ";#" +
                                                                   a.Type + ";#" + a.Winner + ";#" + a.Year).DefaultIfEmpty().ToList();
                m.AltTitle = netflixtitle.ShortTitle;
                m.Rating   = netflixtitle.Rating.RatingType == RatingType.Mpaa ?
                             netflixtitle.Rating.MpaaRating.ToString() : netflixtitle.Rating.TvRating.ToString();
                m.RatingType = netflixtitle.Rating.RatingType;

                foreach (FlixSharp.Holders.FormatAvailability f in netflixtitle.Formats)
                {
                    switch (f.Format)
                    {
                    case "Blu-ray":
                        m.Netflix.Format |= Models.Format.Bluray;
                        break;

                    case "DVD":
                        m.Netflix.Format |= Models.Format.DVD;
                        break;

                    case "instant":
                        m.Netflix.Format |= Models.Format.Digital;
                        break;
                    }
                }
                //m.Netflix.RelatedTitles = netflixmovie.RelatedTitles.Select(t => t.Id).ToList();
                m.Netflix.Synopsis           = netflixtitle.Synopsis;
                m.Netflix.IdUrl              = netflixtitle.IdUrl;
                m.Netflix.Url                = netflixtitle.NetflixSiteUrl;
                m.Netflix.OfficialWebsiteUrl = netflixtitle.NetflixSiteUrl;
                var nfactorids        = netflixtitle.Actors.Select(t => t.Id);
                var matchedactors     = ftc.People.Where(t => nfactorids.Contains(t.Netflix.Id));
                var matchedactorids   = matchedactors.Select(p => p.Netflix.Id);
                var actorsfordatabase = netflixtitle.Actors.Where(t => !matchedactorids.Contains(t.Id));
                foreach (FlixSharp.Holders.Person p in actorsfordatabase)
                {
                    ///1) find the cast and loop through and add the people to the database in a similar manner as AsyncHelpers.GetDatabasePeople
                    FilmTrove.Models.Person ftperson = ftc.People.Local.WhereFirstOrCreate(t => t.Netflix.Id == p.Id);
                    if (ftperson.Name == null || ftperson.Name == "")
                    {
                        ftperson = ftc.People.WhereFirstOrCreate(t => t.Netflix.Id == p.Id);
                        if (ftperson.Name == null || ftperson.Name == "")
                        {
                            GeneralHelpers.FillBasicPerson(ftperson, p);
                            ftc.People.Add(ftperson);
                        }
                    }
                    ///2) add this movie as a new role on the movie
                    Role r = ftc.Roles.Create();
                    r.InRole = RoleType.Actor;
                    r.Movie  = m;
                    r.Person = ftperson;
                    ftc.Roles.Add(r);
                }
                if (m.Roles.Count(c => c.InRole == RoleType.Actor) < nfactorids.Count())
                {
                    ///need to find which roles haven't already been added.
                    var currentroles = m.Roles.Where(r => r.InRole == RoleType.Actor).Select(r => r.Person.PersonId);
                    var actorsfordb  = matchedactors.Where(r => !currentroles.Contains(r.PersonId));
                    foreach (Models.Person p in actorsfordb)
                    {
                        ///2) add this movie as a new role on the movie
                        Role r = ftc.Roles.Create();
                        r.InRole = RoleType.Actor;
                        r.Movie  = m;
                        r.Person = p;
                        ftc.Roles.Add(r);
                    }
                }


                var nfdirectorids        = netflixtitle.Directors.Select(t => t.Id);
                var matcheddirectors     = ftc.People.Where(t => nfdirectorids.Contains(t.Netflix.Id));
                var matcheddirectorids   = matcheddirectors.Select(p => p.Netflix.Id);
                var directorsfordatabase = netflixtitle.Directors.Where(t => !matcheddirectorids.Contains(t.Id));
                foreach (FlixSharp.Holders.Person p in directorsfordatabase)
                {
                    ///1) find the cast and loop through and add the people to the database in a similar manner as AsyncHelpers.GetDatabasePeople
                    FilmTrove.Models.Person ftperson = ftc.People.Local.WhereFirstOrCreate(t => t.Netflix.Id == p.Id);
                    if (ftperson.Name == null || ftperson.Name == "")
                    {
                        ftperson = ftc.People.WhereFirstOrCreate(t => t.Netflix.Id == p.Id);
                        if (ftperson.Name == null || ftperson.Name == "")
                        {
                            GeneralHelpers.FillBasicPerson(ftperson, p);
                            ftc.People.Add(ftperson);
                        }
                    }
                    ///2) add this movie as a new role on the movie
                    Role r = ftc.Roles.Create();
                    r.InRole = RoleType.Director;
                    r.Movie  = m;
                    r.Person = ftperson;
                    ftc.Roles.Add(r);
                }
                if (m.Roles.Count(c => c.InRole == RoleType.Director) < nfdirectorids.Count())
                {
                    ///need to find which roles haven't already been added.
                    var currentroles   = m.Roles.Where(r => r.InRole == RoleType.Director).Select(r => r.Person.PersonId);
                    var directorsfordb = matcheddirectors.Where(r => !currentroles.Contains(r.PersonId));
                    foreach (Models.Person p in directorsfordb)
                    {
                        ///2) add this movie as a new role on the movie
                        Role r = ftc.Roles.Create();
                        r.InRole = RoleType.Director;
                        r.Movie  = m;
                        r.Person = p;
                        ftc.Roles.Add(r);
                    }
                }

                ///3) add all similar titles to the database similar to step 1 for people
                var nftitleids          = netflixtitle.SimilarTitles.Select(t => t.Id + (t.SeasonId != "" ? ";" + t.SeasonId : ""));
                var matchedtitleids     = ftc.Movies.Where(t => nftitleids.Contains(t.Netflix.Id)).Select(t => t.Netflix.Id);
                var titleidsfordatabase = nftitleids.Where(t => !matchedtitleids.Contains(t));
                var titlesfordatabase   = netflixtitle.SimilarTitles.Where(t =>
                {
                    var fullid = t.Id + (t.SeasonId != "" ? ";" + t.SeasonId : "");
                    return(titleidsfordatabase.Contains(fullid));
                });
                foreach (FlixSharp.Holders.Title t in titlesfordatabase)
                {
                    FilmTrove.Models.Movie ftmovie = ftc.Movies.Create();
                    GeneralHelpers.FillBasicTitle(ftmovie, t);

                    ///get the genres that exist in the database (local cache and db)
                    var dbgenreslocal = ftc.Genres.Local.Where(g => t.Genres.Contains(g.Name));
                    var dbgenres      = ftc.Genres.Where(g => t.Genres.Contains(g.Name));
                    ///add them together into one non duplicated list
                    HashSet <Genre> genres = new HashSet <Genre>();
                    genres.AddRange(dbgenres);
                    genres.AddRange(dbgenreslocal);
                    ///get the names of the database genres
                    var genrenames = genres.Select(g => g.Name);
                    ///find the genres on the movie that aren't in the database
                    var missinggenres = t.Genres.Where(g => !genrenames.Contains(g));
                    foreach (String genre in missinggenres)
                    {
                        Genre g = new Genre()
                        {
                            Name = genre
                        };
                        ///add the genre to the list
                        genres.Add(g);
                        ftc.Genres.Add(g);
                    }
                    ///create all the genre-movie records
                    foreach (Genre g in genres)
                    {
                        MovieGenre gi = ftc.GenreItems.Create();
                        gi.Genre = g;
                        gi.Movie = ftmovie;
                        ftc.GenreItems.Add(gi);
                    }
                    ftc.Movies.Add(ftmovie);
                }

                m.Netflix.SimilarTitles = netflixtitle.SimilarTitles.Select(t => t.IdUrl).ToList();
                m.Netflix.NeedsUpdate   = false;

                var             dbgl = ftc.Genres.Local.Where(g => netflixtitle.Genres.Contains(g.Name));
                var             dbg  = ftc.Genres.Where(g => netflixtitle.Genres.Contains(g.Name));
                HashSet <Genre> gs   = new HashSet <Genre>();
                gs.AddRange(dbg);
                gs.AddRange(dbgl);

                var gn  = gs.Select(g => g.Name);
                var mgs = netflixtitle.Genres.Where(g => !gn.Contains(g));
                foreach (String genre in mgs)
                {
                    Genre g = new Genre()
                    {
                        Name = genre
                    };
                    gs.Add(g);
                    ftc.Genres.Add(g);
                }
                //newmovie.Genres = netflixmovie.Genres;
                foreach (Genre g in gs)
                {
                    MovieGenre gi = ftc.GenreItems.Create();
                    gi.Genre = g;
                    gi.Movie = m;
                    ftc.GenreItems.Add(gi);
                }

                m.Netflix.Synopsis = netflixtitle.Synopsis;
                m.Description      = netflixtitle.Synopsis;
            }
            m.ViewCount++;
            ftc.SaveChanges();
            #endregion

            if (m.Netflix.SimilarTitles.Count > 0)
            {
                var similars = m.Netflix.SimilarTitles.Take(20).Select(f =>
                {
                    MatchCollection match = Regex.Matches(f, "[0-9]{3,10}");
                    var r = match.Cast <Match>().Select(t => t.Value).Take(2);
                    return(r.First() + (r.Count() > 1 ? ";" + r.LastOrDefault() : ""));
                });
                ViewBag.Similars = ftc.Movies.Where(t => similars.Contains(t.Netflix.Id)).ToArray();
            }
            ViewBag.Roles = m.Roles;
            ViewBag.Movie = m;

            ViewBag.Id = id;
            return(View());
        }
コード例 #15
0
ファイル: GeneralHelpers.cs プロジェクト: donomans/FilmTrove
        public static List <Models.Movie> GetDatabaseMovies(Titles results)
        {
            var netflixids = results.Select((m) => m.Id + (m.SeasonId != "" ? ";" + m.SeasonId : ""));

            using (FilmTroveContext ftc = new FilmTroveContext())
            {
                ///1) find the matching records from the database
                var matchedmovies = ftc.Movies.Where(m => netflixids.Contains(m.Netflix.Id));
                ///2) find the records that don't have a match
                ///select the ids and get the netflix Ids that aren't in the FT database
                var ftnfids             = matchedmovies.Select(m => m.Netflix.Id);
                var netflixidsunmatched = netflixids.Where(m => !ftnfids.Contains(m));
                //Int32 count = 0;
                foreach (String nid in netflixidsunmatched)
                {
                    ///create FT database records for each of these with the movies basic information for now
                    FilmTrove.Models.Movie  newmovie     = ftc.Movies.Create();
                    FlixSharp.Holders.Title netflixmovie = results.Find(nid);
                    FillBasicTitle(newmovie, netflixmovie);


                    var             dbgenreslocal = ftc.Genres.Local.Where(g => netflixmovie.Genres.Contains(g.Name));
                    var             dbgenres      = ftc.Genres.Where(g => netflixmovie.Genres.Contains(g.Name));
                    HashSet <Genre> genres        = new HashSet <Genre>();
                    genres.AddRange(dbgenres);
                    genres.AddRange(dbgenreslocal);

                    var genrenames    = genres.Select(g => g.Name);
                    var missinggenres = netflixmovie.Genres.Where(g => !genrenames.Contains(g));
                    foreach (String genre in missinggenres)
                    {
                        Genre g = new Genre()
                        {
                            Name = genre
                        };
                        genres.Add(g);
                        ftc.Genres.Add(g);
                    }
                    //newmovie.Genres = netflixmovie.Genres;
                    foreach (Genre g in genres)
                    {
                        MovieGenre gi = ftc.GenreItems.Create();
                        gi.Genre = g;
                        gi.Movie = newmovie;
                        ftc.GenreItems.Add(gi);
                    }
                    ftc.Movies.Add(newmovie);
                }

                //try
                //{
                //count =
                ftc.SaveChanges();
                //}
                //catch (Exception ex)
                //{
                //    ///need to add some sort of logging?

                //}
                //if (count > 0)
                if (matchedmovies.Count() < results.Count())
                {
                    matchedmovies = ftc.Movies.Where(m => netflixids.Contains(m.Netflix.Id));
                }
                //else
                //    return matchedmovies.ToList();

                return(results.Select(m =>
                                      matchedmovies.First(f =>
                                                          f.Netflix.Id == (m.Id + (m.SeasonId != "" ? ";" + m.SeasonId : "")))).ToList());
            }
        }
コード例 #16
0
        public async Task <ContentResult> Filmography(String id, String name)
        {
            FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];

            FilmTrove.Models.Person p = ftc.People.Find(Int32.Parse(id));

            Task <FlixSharp.Holders.Person> nfp = null;

            if (p.Netflix.NeedsUpdate)                                              ///how can i make sure it checks filmography occasionally?
            {
                nfp = Netflix.Fill.People.GetCompletePerson(p.Netflix.IdUrl, true); //Randomized().
            }
            if (p.RottenTomatoes.NeedsUpdate)
            {
            }
            if (p.Imdb.NeedsUpdate)
            {
            }

            if (nfp != null)
            {
                ///1) get filmography
                var netflixperson = await nfp;
                ///2) get the netflixids of all the films
                var netflixfilmographyids = netflixperson.Filmography.Select(t => t.Id + (t.SeasonId != "" ? ";" + t.SeasonId : ""));
                ///3) look up the movies in ft database by netflixids
                var ftmoviesfound = ftc.Movies.Include("Roles").Where(t => netflixfilmographyids.Contains(t.Netflix.Id));
                ///4) check each of those to see they have roles defined (if so then ignore it)
                Dictionary <Movie, Task <People> > actors    = new Dictionary <Movie, Task <People> >();
                Dictionary <Movie, Task <People> > directors = new Dictionary <Movie, Task <People> >();

                foreach (FilmTrove.Models.Movie ftm in ftmoviesfound)
                {
                    if (ftm.Roles.Count < 1)
                    {
                        ///7) make call to actors/directors api
                        //http://api-public.netflix.com/catalog/titles/series/60030701/seasons/60035075
                        directors.Add(ftm, Netflix.Fill.Titles.GetDirectors(ftm.Netflix.IdUrl)); //.Randomized()
                        actors.Add(ftm, Netflix.Fill.Titles.GetActors(ftm.Netflix.IdUrl));       //Randomized().
                    }
                }
                ///5) find the netflix ids that aren't in the database
                var ftmoviesfoundids   = ftmoviesfound.Select(t => t.Netflix.Id);
                var netflixmoviestoadd = netflixperson.Filmography.Where(t => !ftmoviesfoundids.Contains(t.Id));
                ///6) add those movies to the database
                foreach (FlixSharp.Holders.Title title in netflixmoviestoadd)
                {
                    var m = ftc.Movies.Create();
                    GeneralHelpers.FillBasicTitle(m, title);

                    var             dbgenreslocal = ftc.Genres.Local.Where(g => title.Genres.Contains(g.Name));
                    var             dbgenres      = ftc.Genres.Where(g => title.Genres.Contains(g.Name));
                    HashSet <Genre> genres        = new HashSet <Genre>();
                    genres.AddRange(dbgenres);
                    genres.AddRange(dbgenreslocal);

                    var genrenames    = genres.Select(g => g.Name);
                    var missinggenres = title.Genres.Where(g => !genrenames.Contains(g));
                    foreach (String genre in missinggenres)
                    {
                        ftc.Genres.Add(new Genre()
                        {
                            Name = genre
                        });
                    }
                    //newmovie.Genres = netflixmovie.Genres;
                    foreach (Genre g in genres)
                    {
                        MovieGenre gi = ftc.GenreItems.Create();
                        gi.Genre = g;
                        gi.Movie = m;
                        ftc.GenreItems.Add(gi);
                    }
                    ftc.Movies.Add(m);
                    ///7) make call to actors/directors api on each filmography title
                    directors.Add(m, Netflix.Fill.Titles.GetDirectors(m.Netflix.IdUrl)); //Randomized().
                    actors.Add(m, Netflix.Fill.Titles.GetActors(m.Netflix.IdUrl));       //.Randomized()
                }

                ///8) add the people that don't exist to the ftdatabase
                var   actorslist    = actors.Select(a => a);
                var   directorslist = directors.Select(d => d);
                Int32 s             = ftc.SaveChanges();
                foreach (KeyValuePair <Movie, Task <People> > peeps in actorslist)
                {
                    People people = await peeps.Value;
                    if (people.Find(p.Netflix.Id) != null)
                    {
                        ///9) add roles as needed for the original movie now that database has people
                        Role r = ftc.Roles.Create();
                        r.InRole = RoleType.Actor;
                        r.Movie  = peeps.Key;
                        r.Person = p;
                        ftc.Roles.Add(r);
                    }
                    var peopleids        = people.Select(t => t.Id);
                    var matchedpeople    = ftc.People.Where(t => peopleids.Contains(t.Netflix.Id));
                    var matchedpeopleids = matchedpeople.Select(t => t.Netflix.Id);
                    var unmatchedpeople  = peopleids.Where(t => !matchedpeopleids.Contains(t));
                    foreach (String nid in unmatchedpeople)
                    {
                        FilmTrove.Models.Person newperson = ftc.People.Local.WhereFirstOrCreate(t => t.Netflix.Id == nid);
                        if (newperson.Name == null || newperson.Name == "")
                        {
                            newperson = ftc.People.WhereFirstOrCreate(t => t.Netflix.Id == nid);
                            if (newperson.Name == null || newperson.Name == "")
                            {
                                FlixSharp.Holders.Person nperson = people.Find(nid);
                                GeneralHelpers.FillBasicPerson(newperson, nperson);

                                ftc.People.Add(newperson);
                            }
                        }
                    }
                }
                //Int32 c = ftc.SaveChanges();

                foreach (KeyValuePair <Movie, Task <People> > peeps in directorslist)
                {
                    People people = await peeps.Value;
                    if (people.Find(p.Netflix.Id) != null)
                    {
                        ///9) add roles as needed for the original movie now that database has people
                        Role r = ftc.Roles.Create();
                        r.InRole = RoleType.Director;
                        r.Movie  = peeps.Key;
                        r.Person = p;
                        ftc.Roles.Add(r);
                    }
                    var peopleids        = people.Select(t => t.Id);
                    var matchedpeople    = ftc.People.Where(t => peopleids.Contains(t.Netflix.Id));
                    var matchedpeopleids = matchedpeople.Select(t => t.Netflix.Id);
                    var unmatchedpeople  = peopleids.Where(t => !matchedpeopleids.Contains(t));
                    foreach (String nid in unmatchedpeople)
                    {
                        FilmTrove.Models.Person newperson = ftc.People.Local.WhereFirstOrCreate(t => t.Netflix.Id == nid);
                        if (newperson.Name == null || newperson.Name == "")
                        {
                            newperson = ftc.People.WhereFirstOrCreate(t => t.Netflix.Id == nid);
                            if (newperson.Name == null || newperson.Name == "")
                            {
                                FlixSharp.Holders.Person nperson = people.Find(nid);
                                GeneralHelpers.FillBasicPerson(newperson, nperson);

                                ftc.People.Add(newperson);
                            }
                        }
                    }
                }
            }
            p.Netflix.NeedsUpdate = false;
            ftc.SaveChanges();
            ViewBag.Person = p;

            return(new ContentResult()
            {
                Content = "yay"
            });
        }
コード例 #17
0
        public ActionResult NetflixLoginCallback(String oauth_token)
        {
            if (oauth_token != null && oauth_token != "")
            {
                Object oauth_token_secret = Session["oauth_token_secret"];
                if (oauth_token_secret == null)
                {
                    ViewBag.Success = false;
                    ViewBag.Message = "Well, this ended poorly.  Sorry.  Let's try again.";
                    return(View());
                }
                //Netflix.Login n = new Netflix();
                String accessUrl = Netflix.Login.SetCredentials(
                    "7qf3845qydavuucmhj96b6hd",
                    "5jYe5FVhhF",
                    "FilmTrove").GetAccessUrl(oauth_token, oauth_token_secret.ToString());

                String oauthstuff = "";
                using (WebClient web = new WebClient())
                {
                    oauthstuff = web.DownloadString(accessUrl);
                }
                String[] oauthsplits = oauthstuff.Split(new[] { "&", "=" }, StringSplitOptions.None);

                String new_oauth_token        = "";
                String new_oauth_token_secret = "";
                String user_id = "";

                Int32  counter = 0;
                String stash   = "";

                foreach (String s in oauthsplits)
                {
                    if (counter % 2 == 0)
                    {
                        stash = s;
                    }
                    else
                    {
                        switch (stash)
                        {
                        case "oauth_token":
                            new_oauth_token = s;
                            break;

                        case "user_id":
                            user_id = s;
                            break;

                        case "oauth_token_secret":
                            new_oauth_token_secret = s;
                            break;

                        default:
                            break;
                        }
                    }
                    counter++;
                }
                FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"];
                UserProfile      up  = ftc.UserProfiles.Find(WebSecurity.CurrentUserId);
                up.NetflixAccount.Token       = new_oauth_token;
                up.NetflixAccount.TokenSecret = new_oauth_token_secret;
                up.NetflixAccount.UserId      = user_id;

                ftc.SaveChanges();
                ViewBag.NetflixLinked = true;
                ViewBag.Success       = true;
                ViewBag.Message       = "Successfully linked your Netflix account";
                return(View("Me"));
            }
            else
            {
                ViewBag.NetflixLinked = null;
                ViewBag.Success       = false;
                ViewBag.Message       = "We screwed some part of the login process.  Sorry.  Let's try again.";
                return(View());
            }
        }