Example #1
0
        public ObservableCollection <FilmTitle> DeserializeData()
        {
            GetFilm getFilm = new GetFilm();
            ObservableCollection <FilmTitle> collection = new ObservableCollection <FilmTitle>();

            List <MyList> myList = new List <MyList>();

            if (!File.Exists("MyList.json"))
            {
                using (FileStream create = File.Create("MyList.json")) { }
            }

            try
            {
                DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List <MyList>));
                using (FileStream fs = File.OpenRead("MyList.json"))
                    myList = jsonSerializer.ReadObject(fs) as List <MyList>;
            }
            catch (Exception) { }


            foreach (var i in myList)
            {
                var col = getFilm.GetFilmWithId(i.id);
                var a   = new FilmTitle()
                {
                    Id = col.Id, Title = col.Title, Vote_average = col.Vote_average, Poster_path = col.Poster_path, Overview = col.Overview, Release_date = col.Release_date
                };
                collection.Add(a);
            }
            return(collection);
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("FilmTitleID,GenreID,CertificateID,FilmName,FilmStory,FilmReleaseDate,FilmDuration,FilmAdditionalInfo")] FilmTitle filmTitle)
        {
            if (id != filmTitle.FilmTitleID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(filmTitle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FilmTitleExists(filmTitle.FilmTitleID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CertificateID"] = new SelectList(_context.Certificate, "CertificateID", "CertificateName", filmTitle.CertificateID);
            ViewData["GenreID"]       = new SelectList(_context.Genre, "GenreID", "GenreName", filmTitle.GenreID);
            return(View(filmTitle));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("FilmTitleID,GenreID,CertificateID,FilmName,FilmStory,FilmReleaseDate,FilmDuration,FilmAdditionalInfo")] FilmTitle filmTitle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(filmTitle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CertificateID"] = new SelectList(_context.Certificate, "CertificateID", "CertificateName", filmTitle.CertificateID);
            ViewData["GenreID"]       = new SelectList(_context.Genre, "GenreID", "GenreName", filmTitle.GenreID);
            return(View(filmTitle));
        }
Example #4
0
        public ObservableCollection <FilmTitle> GetAll()
        {
            ObservableCollection <FilmTitle> filmTitles = new ObservableCollection <FilmTitle>();

            string    url       = "https://api.themoviedb.org/3/movie/now_playing?page=1&language=en-US&api_key=6adcfee0eaa50e9be7a88a0ddd5db2dd";
            WebClient webClient = new WebClient();
            string    json      = webClient.DownloadString(url);

            JObject obj = JObject.Parse(json);



            foreach (var i in obj["results"])
            {
                string overview = "";
                if (i["overview"].ToString().Length > 210)
                {
                    overview = i["overview"].ToString().Remove(210) + "...";
                }
                else
                {
                    overview = i["overview"].ToString();
                }
                var a = new FilmTitle()
                {
                    Id           = Convert.ToInt32(i["id"]),
                    Vote_average = Convert.ToDouble(i["vote_average"]),
                    Title        = i["title"].ToString(),
                    Release_date = i["release_date"].ToString(),
                    Overview     = overview,
                    Poster_path  = "https://image.tmdb.org/t/p/w185_and_h278_bestv2/" + i["poster_path"].ToString() + "?resize=300"
                };
                filmTitles.Add(a);
            }

            return(filmTitles);
        }
        public static void Initialize(DVDContext context)
        {
            context.Database.EnsureCreated();

            // Look for any Actors.
            if (context.Actors.Any())
            {
                return;   // DB has been seeded
            }

// Actors
            var actors = new Actor[]
            {
                new Actor {
                    ActorID       = 101,
                    ActorFullName = "Leonardo DiCaprio",
                    ActorNotes    = "Es un actor, productor de cine."
                },
                new Actor {
                    ActorID       = 102,
                    ActorFullName = "Katherine Elizabeth Winslet",
                    ActorNotes    = "Nacida en una familia de actores."
                },
                new Actor {
                    ActorID       = 103,
                    ActorFullName = "Billy Zane ",
                    ActorNotes    = "Conocido como Billy Zane, es un actor y director estadounidense."
                },
                new Actor {
                    ActorID       = 104,
                    ActorFullName = "Frances Fisher ",
                    ActorNotes    = "Ha aparecido en películas como Unforgiven, Titanic, Gone in Sixty Seconds y True Crime (1999)."
                },
                new Actor {
                    ActorID       = 105,
                    ActorFullName = "Gloria Stuart ",
                    ActorNotes    = "Actriz estadounidense, adquirió reconocimiento internacional por su papel de Rose DeWitt Bukater en la película Titanic (1997)."
                }
            };

            foreach (Actor s in actors)
            {
                context.Actors.Add(s);
            }
            context.SaveChanges();

// RoleType

            var roleTypes = new RoleType[]
            {
                new RoleType {
                    RoleTypeID = 1,
                    RoleTypes  = " Jack Dawson, Principal"
                },
                new RoleType {
                    RoleTypeID = 2,
                    RoleTypes  = " Rose DeWitt Bukater, Principal"
                },
                new RoleType {
                    RoleTypeID = 3,
                    RoleTypes  = " Caledon Nathan , Secundario"
                },
                new RoleType {
                    RoleTypeID = 4,
                    RoleTypes  = " Ruth DeWitt Bukater, Secundario"
                },
                new RoleType {
                    RoleTypeID = 5,
                    RoleTypes  = " Rose Dawson (Anciana), Principal"
                }
            };

            foreach (RoleType i in roleTypes)
            {
                context.RoleTypes.Add(i);
            }
            context.SaveChanges();

// Producers
            var producers = new Producer[]
            {
                new Producer {
                    ProducerID          = 1,
                    ProducerName        = "James Cameron",
                    ContactEmailAddress = "*****@*****.**",
                    Website             = "https://www.imdb.com/name/nm0000116/"
                },
                new Producer {
                    ProducerID          = 2,
                    ProducerName        = "Jon Landau ",
                    ContactEmailAddress = "*****@*****.**",
                    Website             = "https://www.imdb.com/name/nm0484457/"
                },
                new Producer {
                    ProducerID          = 3,
                    ProducerName        = "Guillermo del Toro",
                    ContactEmailAddress = "*****@*****.**",
                    Website             = "https://deltorofilms.com/"
                },
                new Producer {
                    ProducerID          = 4,
                    ProducerName        = "Steven S. DeKnight",
                    ContactEmailAddress = "*****@*****.**",
                    Website             = "https://www.imdb.com/name/nm0000116/"
                },
            };

            foreach (Producer i in producers)
            {
                context.Producers.Add(i);
            }
            context.SaveChanges();

// FilmCertificate
            var filmCertificates = new FilmCertificate[]
            {
                new FilmCertificate {
                    CertificateID = 1,
                    Certificate   = "PG-13"
                },
                new FilmCertificate {
                    CertificateID = 2,
                    Certificate   = "PG"
                },
                new FilmCertificate {
                    CertificateID = 3,
                    Certificate   = "G"
                },
                new FilmCertificate {
                    CertificateID = 4,
                    Certificate   = "R"
                },
                new FilmCertificate {
                    CertificateID = 5,
                    Certificate   = "NR"
                }
            };

            foreach (FilmCertificate i in filmCertificates)
            {
                context.FilmCertificates.Add(i);
            }
            context.SaveChanges();

// FilmGenres
            var filmGenres = new FilmGenre[]
            {
                new FilmGenre {
                    GenreID = 1,
                    Genre   = "Drama"
                },
                new FilmGenre {
                    GenreID = 2,
                    Genre   = "Romance"
                },
                new FilmGenre {
                    GenreID = 3,
                    Genre   = "Comedia"
                },
                new FilmGenre {
                    GenreID = 4,
                    Genre   = "Ficción"
                },
                new FilmGenre {
                    GenreID = 5,
                    Genre   = "Acción"
                },
                new FilmGenre {
                    GenreID = 6,
                    Genre   = "Documental"
                }
            };

            foreach (FilmGenre i in filmGenres)
            {
                context.FilmGenres.Add(i);
            }
            context.SaveChanges();
// Film Titles

            var filmTitles = new FilmTitle[]
            {
                new FilmTitle {
                    FilmTitleID        = 10,
                    FilmTitles         = "Titanic",
                    FilmStory          = "Jack, un joven artista, en una partida de cartas gana un pasaje para América, en el Titanic, el trasatlántico más grande y seguro jamás construido.",
                    FilmReleaseDate    = DateTime.Parse("1997-12-19"),
                    FilmDuration       = 195,
                    GenreID            = filmGenres.Single(c => c.GenreID == 1).GenreID,
                    CertificateID      = filmCertificates.Single(c => c.CertificateID == 1).CertificateID,
                    FilmAdditionalInfo = "Titanic obtuvo muy buenas críticas tras su estreno."
                }
            };

            foreach (FilmTitle i in filmTitles)
            {
                context.FilmTitles.Add(i);
            }
            context.SaveChanges();


// Film Titles Producer

            var filmTitlesProducers = new FilmTitlesProducer[]
            {
                new FilmTitlesProducer {
                    ProducerID  = producers.Single(c => c.ProducerID == 1).ProducerID,
                    FilmTitleID = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID
                },
                new FilmTitlesProducer {
                    ProducerID  = producers.Single(c => c.ProducerID == 2).ProducerID,
                    FilmTitleID = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID
                },
            };

            foreach (FilmTitlesProducer i in filmTitlesProducers)
            {
                context.FilmTitlesProducers.Add(i);
            }
            context.SaveChanges();

// FilmsActorRoles
            var filmsActorRols = new FilmsActorRol[]
            {
                new FilmsActorRol {
                    FilmTitleID          = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID,
                    ActorID              = actors.Single(c => c.ActorID == 101).ActorID,
                    RoleTypeID           = roleTypes.Single(c => c.RoleTypeID == 1).RoleTypeID,
                    CharacterName        = " Jack Dawson",
                    CharacterDescription = "Un sujeto de Wisconsin de clase baja que ha viajado por varias partes del mundo."
                },
                new FilmsActorRol {
                    FilmTitleID          = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID,
                    ActorID              = actors.Single(c => c.ActorID == 102).ActorID,
                    RoleTypeID           = roleTypes.Single(c => c.RoleTypeID == 2).RoleTypeID,
                    CharacterName        = "Kate Winslet",
                    CharacterDescription = "Una joven de diecisiete años originaria de Filadelfia."
                },
                new FilmsActorRol {
                    FilmTitleID          = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID,
                    ActorID              = actors.Single(c => c.ActorID == 103).ActorID,
                    RoleTypeID           = roleTypes.Single(c => c.RoleTypeID == 3).RoleTypeID,
                    CharacterName        = "Billy Zane ",
                    CharacterDescription = "Un adinerado de treinta años de edad, funge como el antagonista de la película."
                },
                new FilmsActorRol {
                    FilmTitleID          = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID,
                    ActorID              = actors.Single(c => c.ActorID == 104).ActorID,
                    RoleTypeID           = roleTypes.Single(c => c.RoleTypeID == 4).RoleTypeID,
                    CharacterName        = "Ruth DeWitt Bukater ",
                    CharacterDescription = "Desea que su hija contraiga matrimonio con Cal."
                },
                new FilmsActorRol {
                    FilmTitleID          = filmTitles.Single(c => c.FilmTitleID == 10).FilmTitleID,
                    ActorID              = actors.Single(c => c.ActorID == 105).ActorID,
                    RoleTypeID           = roleTypes.Single(c => c.RoleTypeID == 5).RoleTypeID,
                    CharacterName        = "Rose Dawson Calvert",
                    CharacterDescription = "La misma protagonista solo que con una edad de 100 años."
                }
            };

            foreach (FilmsActorRol i in filmsActorRols)
            {
                context.FilmsActorRols.Add(i);
            }
            context.SaveChanges();
// --------------------------------------------------------------------------------------------------
        }
Example #6
0
        public void RunSQL_Compact()
        {
            using (DvdContext db = new DvdContext())
            {
                // film generes
                FilmGenere actionGenere = db.FilmGeneres.Where(g => g.Name == "Action").SingleOrDefault();

                FilmGenere scifiGenere = db.FilmGeneres.Where(g => g.Name == "SciFi").SingleOrDefault();

                // find the producer
                Producer jjAbrams = db.Producers.Where(p => p.FullName == "J.J. Abrams").SingleOrDefault();

                // we found the producer

                if (jjAbrams != null)
                {
                    // add some films to that producer

                    FilmTitle film1 = new FilmTitle()
                    {
                        Title = "Mission: Impossible III",

                        Duration = 126,

                        Story = "Ethan Hunt comes face to face with a dangerous and ...",

                        FilmGenere = actionGenere
                    };

                    film1.Producers = new List <Producer>();

                    film1.Producers.Add(jjAbrams);

                    db.FilmTitles.Add(film1);

                    FilmTitle film2 = new FilmTitle()
                    {
                        Title = "Star Trek Into Darkness",

                        Duration = 132,

                        Story = "After the crew of the Enterprise find an unstoppable force  ...",

                        FilmGenere = scifiGenere
                    };

                    film2.Producers = new List <Producer>();

                    film2.Producers.Add(jjAbrams);

                    db.FilmTitles.Add(film2);

                    // add some film roles
                    Role leadRole = db.Roles.Where(r => r.Name == "Lead").SingleOrDefault();

                    Role supportingRole = db.Roles.Where(r => r.Name == "Supporting").SingleOrDefault();

                    // load the actors
                    Actor tom = db.Actors.Where(a => a.Surname == "Cruise").SingleOrDefault();

                    Actor quinto = db.Actors.Where(a => a.Surname == "Quinto").SingleOrDefault();

                    Actor pine = db.Actors.Where(a => a.Surname == "Pine").SingleOrDefault();

                    // add filmroles

                    db.FilmActorRoles.Add(new FilmActorRole()
                    {
                        Actor = tom,

                        Role = leadRole,

                        FilmTitle = film1,

                        Character = "Ethan",

                        Description = "Ethan Hunt comes face to face with a dangerous and sadistic arms dealer while trying to keep his identity secret in order to protect his girlfriend."
                    });

                    db.FilmActorRoles.Add(new FilmActorRole()
                    {
                        Actor = pine,

                        Role = leadRole,

                        FilmTitle = film2,

                        Character = "Kirk",

                        Description = "Captain Kirk"
                    });

                    db.FilmActorRoles.Add(new FilmActorRole()
                    {
                        Actor = quinto,

                        Role = supportingRole,

                        FilmTitle = film2,

                        Character = "Spock",

                        Description = "Spock was born in 2230, in the city of Shi'Kahr on the planet Vulcan"
                    });
                }

                // save data to db

                db.SaveChanges();

                db.Dispose();
            }
        }