示例#1
0
        /* public ActionResult Edit(int? ProductionCompany_id)
         * {
         *   var Edit = list1.Where(x => x.ProductionCompany_id == ProductionCompany_id).FirstOrDefault();
         *   return View(Edit);
         * }
         * [HttpPost]
         * public ActionResult Edit(ProductionCompany pc)
         * {
         *   SqlConnection con = new SqlConnection(CS);
         *   con.Open();
         *   SqlCommand cmd = new SqlCommand("spUpdate1", con);
         *   cmd.CommandType = System.Data.CommandType.StoredProcedure;
         *   cmd.Parameters.AddWithValue("@ProductionCompany_name", pc.ProductionCompany_name);
         *   cmd.Parameters.AddWithValue("@Year_Of_Establish", pc.Year_Of_Establish);
         *   cmd.Parameters.AddWithValue("@ChairMan", pc.ChairMan);
         *   cmd.Parameters.AddWithValue("@Founder", pc.Founder);
         *   cmd.ExecuteNonQuery();
         *   ViewBag.Msg2 = "Updated successfully!";
         *   con.Close();
         *
         *   return View(pc);
         * }*/
        public ActionResult Edit(int id)
        {
            try
            {
                ProductionCompany pc = new ProductionCompany();

                SqlConnection con = new SqlConnection(CS);
                SqlCommand    cmd = new SqlCommand("select * from ProductionCompany where ProductionCompany_id=" + id, con);
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        pc.ProductionCompany_id   = Convert.ToInt32(dr["ProductionCompany_id"]);
                        pc.ProductionCompany_name = dr["ProductionCompany_name"].ToString();
                        pc.Year_Of_Establish      = Convert.ToInt32(dr["Year_Of_Establish"]);
                        pc.ChairMan = dr["ChairMan"].ToString();
                        pc.Founder  = dr["Founder"].ToString();
                    }
                }
                con.Close();
                //var Edit = list4.Where(x => x.Movie_id == Movie_id).FirstOrDefault();
                return(View(pc));
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                throw ex;
            }
        }
示例#2
0
        public async Task <IActionResult> Update(ProductionCompany pc, IFormFile mLogo)
        {
            if (ModelState.IsValid)
            {
                string path = pc.Logo;
                if (mLogo != null)
                {
                    path = "Images/Production/" + mLogo.FileName;
                    using (var stream = new FileStream(Path.Combine(hostingEnvironment.WebRootPath, path), FileMode.Create))
                    {
                        await mLogo.CopyToAsync(stream);
                    }
                }

                var productionCompany = new ProductionCompany()
                {
                    Id                = pc.Id,
                    Name              = pc.Name,
                    Logo              = path.Substring(0, 2) == "~/" ? path : "~/" + path,
                    AnnualRevenue     = pc.AnnualRevenue,
                    EstablishmentDate = pc.EstablishmentDate
                };

                context.Update(productionCompany);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(pc));
            }
        }
示例#3
0
        public async Task <IActionResult> Create(ProductionCompany pc, IFormFile Logo)
        {
            if (Logo == null)
            {
                ModelState.AddModelError(nameof(pc.Logo), "Please select logo file");
            }

            if (ModelState.IsValid)
            {
                string path = "Images/Production/" + Logo.FileName;
                using (var stream = new FileStream(Path.Combine(hostingEnvironment.WebRootPath, path), FileMode.Create))
                {
                    await Logo.CopyToAsync(stream);
                }

                var productionCompany = new ProductionCompany()
                {
                    Name              = pc.Name,
                    Logo              = "~/" + path,
                    AnnualRevenue     = pc.AnnualRevenue,
                    EstablishmentDate = pc.EstablishmentDate
                };

                context.Add(productionCompany);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
示例#4
0
        public async Task <int> Handle(CreateProductionCompanyCommand request, CancellationToken cancellationToken)
        {
            var productionCompany = new ProductionCompany(request.Name);
            await _repository.AddProductionCompanyAsync(productionCompany);

            return(productionCompany.Id);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductionCompany productionCompany = db.ProductionCompanies.Find(id);

            db.ProductionCompanies.Remove(productionCompany);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void ReduceByCompany()
        {
            Dictionary <ProductionCompany, double> LoadedData = new Dictionary <ProductionCompany, double>();

            // Load txt
            using (StreamReader sr = new StreamReader("Svereduce.txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[]          splitter = line.Split(';');
                    ProductionCompany pc       = new ProductionCompany();
                    pc.id   = Int32.Parse(splitter[0]);
                    pc.name = splitter[1].Split(' ')[0];
                    double value = Double.Parse(splitter[2]);

                    LoadedData.Add(pc, value);
                }
            }
            // Reduce
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("=== Reducing by company ===");
            Console.WriteLine();
            Console.WriteLine();
            var valuePairs = LoadedData.GroupBy(val => val.Key.name).ToDictionary(k => k.Key, v => v.ToDictionary(k1 => k1.Key, v1 => v1.Value));

            Dictionary <ProductionCompany, double> Reduced = new Dictionary <ProductionCompany, double>();

            foreach (var item in valuePairs)
            {
                double            sum = 0;
                ProductionCompany pc  = new ProductionCompany();
                foreach (var value in item.Value)
                {
                    sum += value.Value;
                    pc   = value.Key;
                }
                Reduced.Add(pc, sum);
            }

            Console.WriteLine("===Reduced===");
            foreach (var item in Reduced)
            {
                Console.WriteLine(item.Key.name + " : " + item.Value);
            }

            // Upis finalnog reduca u txt fajl
            using (StreamWriter sw = new StreamWriter("finalReduce.txt"))
            {
                foreach (var item in Reduced)
                {
                    sw.WriteLine(item.Key.id + ";" + item.Key.name + ";" + item.Value);
                }
            }
        }
 public ActionResult Edit([Bind(Include = "description,headquarters,homepage,id,logo_path,name,origin_country")] ProductionCompany productionCompany)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productionCompany).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productionCompany));
 }
 public ActionResult Edit([Bind(Include = "id,name,email,address,phone")] ProductionCompany productionCompany)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productionCompany).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productionCompany));
 }
        private async void lbProductionCompanies_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbProductionCompanies.SelectedIndex >= 0)
            {
                ProductionCompany pc  = u.GetProductionCompany(lbProductionCompanies.SelectedItem.ToString());
                Image             img = await pc.GetLogo(TmdbWrapper.Utilities.LogoSize.w45);

                pbMasterLogo.BackgroundImage = img;
            }
        }
示例#10
0
        private static void AddProductionCompany()
        {
            Clear();

            bool customerExists = false;
            bool inCorrectKey   = true;
            bool shouldNotExit  = true;



            do
            {
                WriteLine("Namn: ");
                string name = ReadLine();

                ProductionCompany productionCompany = new ProductionCompany(name);

                WriteLine("Är detta korrekt? (J)a eller (N)ej");

                ConsoleKeyInfo consoleKeyInfo;

                do
                {
                    consoleKeyInfo = ReadKey(true);
                    inCorrectKey   = !(consoleKeyInfo.Key == ConsoleKey.J || consoleKeyInfo.Key == ConsoleKey.N);
                } while (inCorrectKey);


                if (consoleKeyInfo.Key == ConsoleKey.J)
                {
                    bool isCompany = context.ProductionCompany.Any(p => p.Name == name);

                    if (!isCompany)
                    {
                        context.ProductionCompany.Add(productionCompany);
                        context.SaveChanges();

                        shouldNotExit = false;
                        Clear();
                        WriteLine("Produktionsbolag registrerat");
                        Thread.Sleep(1000);
                    }
                    else if (isCompany)
                    {
                        shouldNotExit = false;
                        Clear();
                        WriteLine("Produktionsbolag redan registrerat");
                        Thread.Sleep(1000);
                    }
                }

                Clear();
            } while (shouldNotExit);
        }
        public ActionResult Create([Bind(Include = "description,headquarters,homepage,id,logo_path,name,origin_country")] ProductionCompany productionCompany)
        {
            if (ModelState.IsValid)
            {
                db.ProductionCompanies.Add(productionCompany);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productionCompany));
        }
        public ActionResult Create([Bind(Include = "id,name,email,address,phone")] ProductionCompany productionCompany)
        {
            if (ModelState.IsValid)
            {
                db.ProductionCompanies.Add(productionCompany);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productionCompany));
        }
        public int Create(ProductionCompany pdComp)
        {
            string sqlString = "INSERT INTO ProductionCompany VALUES(@pdCompName,@pdDescription)";
            var    cmd       = new SqlCommand(sqlString);

            cmd.Parameters.AddWithValue("@pdCompName", pdComp.PDCompanyName);
            cmd.Parameters.AddWithValue("@pdDescription", pdComp.Description);

            int rowsAffected = DataAccessHelper.ExecuteNonQuery(cmd);

            return(rowsAffected);
        }
        public ProductionCompany GetProductionCompanyFromDataRow(DataRow dtr)
        {
            if (dtr != null)
            {
                ProductionCompany prodCompResult = new ProductionCompany();
                prodCompResult.PDCompanyID   = dtr["PDCompanyID"].ToString();
                prodCompResult.PDCompanyName = dtr["PDCompanyName"].ToString();
                prodCompResult.Description   = dtr["Description"].ToString();
                return(prodCompResult);
            }

            return(null);
        }
示例#15
0
        //----------------------------------------------------------------//

        public static ProductionCompany MapCompany(ProductionCompanyDto companyDto)
        {
            ProductionCompany company = new ProductionCompany()
            {
                Name = companyDto.Name,
                //Description = companyDto.Description,
                //Headquaters = companyDto.Headquarters,
                //Origin_Country = companyDto.Origin_country,
                //Parent_Company = companyDto.Parent_Company
            };

            return(company);
        }
        public int Save(ProductionCompany pdComp)
        {
            string sqlString = "UPDATE ProductionCompany SET " +
                               "PDCompanyName=@pdCompName, Description=@description WHERE PDCompanyID = @pdCompId";
            var cmd = new SqlCommand(sqlString);

            cmd.Parameters.AddWithValue("@pdCompName", pdComp.PDCompanyName);
            cmd.Parameters.AddWithValue("@description", pdComp.Description);
            cmd.Parameters.AddWithValue("@pdCompId", pdComp.PDCompanyID);

            int rowsAffected = DataAccessHelper.ExecuteNonQuery(cmd);

            return(rowsAffected);
        }
        // GET: ProductionCompanies/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductionCompany productionCompany = db.ProductionCompanies.Find(id);

            if (productionCompany == null)
            {
                return(HttpNotFound());
            }
            return(View(productionCompany));
        }
        public int Delete(ProductionCompany pdComp)
        {
            if (GetCountAssociatedShows(pdComp.PDCompanyID) < 1)
            {
                string sqlString = "DELETE FROM ProductionCompany WHERE PDCompanyID = @pdCompID";
                var    cmd       = new SqlCommand(sqlString);
                cmd.Parameters.AddWithValue("@pdCompID", pdComp.PDCompanyID);

                int rowsAffected = DataAccessHelper.ExecuteNonQuery(cmd);
                return(rowsAffected);
            }
            else
            {
                return(-1);
            }
        }
示例#19
0
        public ActionResult ProductionCompany(ProductionCompany pc)
        {
            SqlConnection con = new SqlConnection(CS);

            con.Open();
            SqlCommand cmd = new SqlCommand("spAdd1", con);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ProductionCompany_name", pc.ProductionCompany_name);
            cmd.Parameters.AddWithValue("@Year_OF_Establish", pc.Year_Of_Establish);
            cmd.Parameters.AddWithValue("@Chairman", pc.ChairMan);
            cmd.Parameters.AddWithValue("@Founder", pc.Founder);
            cmd.ExecuteNonQuery();
            ViewBag.Msg2 = "Added successfully!";
            con.Close();
            return(View());
        }
        public void ReduceAll()
        {
            Dictionary <ProductionCompany, double> FinalReduceDictionary = new Dictionary <ProductionCompany, double>();
            Dictionary <ProductionCompany, double> AllTxtDictionary      = new Dictionary <ProductionCompany, double>();

            // Iscitaj sve txt fajlove popuni dictionary
            int[] fileIds = new int[] { 5002, 5003 };
            for (int i = 0; i < fileIds.Length; i++)
            {
                using (StreamReader sr = new StreamReader("reduced-" + fileIds[i] + ".txt"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[]          splitter = line.Split(';');
                        ProductionCompany pc       = new ProductionCompany();
                        pc.id   = Int32.Parse(splitter[0]);
                        pc.name = splitter[1];
                        double value = Double.Parse(splitter[2]);

                        AllTxtDictionary.Add(pc, value);
                    }
                }
            }

            // Uradi reduce
            FinalReduceDictionary = FinalReduce(AllTxtDictionary);

            PrintReduced(FinalReduceDictionary);


            //upisati sve vredosti u txt fajl


            using (StreamWriter sw = new StreamWriter("Svereduce.txt"))
            {
                foreach (var item in FinalReduceDictionary)
                {
                    sw.WriteLine(item.Key.id + ";" + item.Key.name + ";" + item.Value);
                }
            }

            ReduceByCompany();
        }
        public Dictionary <ProductionCompany, double> FinalReduce(Dictionary <ProductionCompany, double> AllTxtDictionary)
        {
            var subTxtDictionary = AllTxtDictionary.GroupBy(val => val.Key.id).ToDictionary(k => k.Key, v => v.ToDictionary(k1 => k1.Key, v1 => v1.Value));

            Dictionary <ProductionCompany, double> Reduced = new Dictionary <ProductionCompany, double>();

            foreach (var item in subTxtDictionary)
            {
                double            sum = 0;
                ProductionCompany pc  = new ProductionCompany();
                foreach (var value in item.Value)
                {
                    sum += value.Value;
                    pc   = value.Key;
                }
                Reduced.Add(pc, sum);
            }

            return(Reduced);
        }
        public void Reduce(Dictionary <ProductionCompany, double> MapResultDictionary, string fileId)
        {
            Console.WriteLine("Reducing started");
            var subDictionary = MapResultDictionary.GroupBy(val => val.Key.id).ToDictionary(k => k.Key, v => v.ToDictionary(k1 => k1.Key, v1 => v1.Value)); // dictionary medju kljuc-id, vrednost- svi koji pripadaju tom id-iju

            Dictionary <ProductionCompany, double> Reduced = new Dictionary <ProductionCompany, double>();                                                  //krajnji koji cemo popuniti


            foreach (var item in subDictionary) //nakon reduce
            {
                double            sum = 0;
                ProductionCompany pc  = new ProductionCompany();
                foreach (var value in item.Value)
                {
                    sum += value.Value;
                    pc   = value.Key;
                }
                Reduced.Add(pc, sum);
            }

            Console.WriteLine("===Reduced==="); //ispis konacnog
            foreach (var item in Reduced)
            {
                Console.WriteLine(item.Key.name + " : " + item.Value);
            }


            if (fileId != null)// Upis u txt fajlove
            {
                using (StreamWriter sw = new StreamWriter("reduced-" + fileId + ".txt"))
                {
                    foreach (var item in Reduced)
                    {
                        sw.WriteLine(item.Key.id + ";" + item.Key.name + ";" + item.Value);
                    }
                }
            }
        }
示例#23
0
        public async Task AddProductionCompanyAsync(ProductionCompany productionCompany)
        {
            await _dbContext.ProductionCompanies.AddAsync(productionCompany);

            await _dbContext.SaveChangesAsync();
        }
 async Task <KeyValuePair <ProductionCompany, SearchResult> > LookupMoviesForCompanyId(ProductionCompany company) => new KeyValuePair <ProductionCompany, SearchResult>(company, await _movieService.GetMoviesByCompany(company.Id));
示例#25
0
        public async Task <Abstraction.Model.Movie> Merge(Abstraction.Model.Movie movieNew)
        {
            var movieOld = await movieQuery.FirstOrDefaultAsync(e => e.Title == movieNew.Title && e.ReleaseYear == movieNew.ReleaseYear);

            if (movieOld == null)
            {
                movieOld = new Abstraction.Model.Movie
                {
                    Key                 = Guid.NewGuid(),
                    Title               = movieNew.Title,
                    ReleaseYear         = movieNew.ReleaseYear,
                    Actors              = new List <Actor>(),
                    Directors           = new List <Director>(),
                    Distributors        = new List <Distributor>(),
                    FilmingLocations    = new List <FilmingLocation>(),
                    ProductionCompanies = new List <ProductionCompany>(),
                    Writers             = new List <Writer>()
                };

                db.Insert(new Entity.Movie
                {
                    Key         = movieOld.Key,
                    Title       = movieOld.Title,
                    ReleaseYear = movieOld.ReleaseYear
                });
            }

            if (movieNew.Actors.Any())
            {
                var names          = movieNew.Actors.Select(e => e.FullName);
                var existingActors = await db.Actors.Where(e => names.Contains(e.FullName)).ToListAsync();

                foreach (var name in names)
                {
                    if (movieOld.Actors.Any(e => e.FullName == name))
                    {
                        continue;
                    }

                    var entity = existingActors.FirstOrDefault(e => e.FullName == name);

                    if (entity == null)
                    {
                        entity = new Actor
                        {
                            Key      = Guid.NewGuid(),
                            FullName = name
                        };
                        db.Insert(entity);
                    }

                    db.Insert(new Entity.MovieActor {
                        MovieKey = movieOld.Key, ActorKey = entity.Key
                    });
                }
            }

            if (movieNew.Directors.Any())
            {
                var names             = movieNew.Directors.Select(e => e.FullName);
                var existingDirectors = await db.Directors.Where(e => names.Contains(e.FullName)).ToListAsync();

                foreach (var name in names)
                {
                    if (movieOld.Directors.Any(e => e.FullName == name))
                    {
                        continue;
                    }

                    var entity = existingDirectors.FirstOrDefault(e => e.FullName == name);

                    if (entity == null)
                    {
                        entity = new Director
                        {
                            Key      = Guid.NewGuid(),
                            FullName = name
                        };
                        db.Insert(entity);
                    }

                    db.Insert(new Entity.MovieDirector {
                        MovieKey = movieOld.Key, DirectorKey = entity.Key
                    });
                }
            }

            if (movieNew.Distributors.Any())
            {
                var names = movieNew.Distributors.Select(e => e.Name);
                var existingDistributors = await db.Distributors.Where(e => names.Contains(e.Name)).ToListAsync();

                foreach (var name in names)
                {
                    if (movieOld.Distributors.Any(e => e.Name == name))
                    {
                        continue;
                    }

                    var entity = existingDistributors.FirstOrDefault(e => e.Name == name);

                    if (entity == null)
                    {
                        entity = new Distributor
                        {
                            Key  = Guid.NewGuid(),
                            Name = name
                        };
                        db.Insert(entity);
                    }

                    db.Insert(new Entity.MovieDistributor {
                        MovieKey = movieOld.Key, DistributorKey = entity.Key
                    });
                }
            }

            if (movieNew.FilmingLocations.Any())
            {
                // Addresses are in a geocoding module and they have to be pre-filled by the callee.
                if (movieNew.FilmingLocations.All(e => e.AddressKey == default(Guid)))
                {
                    throw new ArgumentException("The addresses don't have keys set.", nameof(movieNew.FilmingLocations));
                }

                foreach (var location in movieNew.FilmingLocations)
                {
                    if (movieOld.FilmingLocations.Any(e => e.AddressKey == location.AddressKey))
                    {
                        continue;
                    }

                    db.Insert(new Entity.FilmingLocation
                    {
                        Key        = location.Key,
                        MovieKey   = movieOld.Key,
                        AddressKey = location.AddressKey,
                        FunFact    = location.FunFact
                    });
                }
            }

            if (movieNew.ProductionCompanies.Any())
            {
                var names             = movieNew.ProductionCompanies.Select(e => e.Name);
                var existingCompanies = await db.ProductionCompanies.Where(e => names.Contains(e.Name)).ToListAsync();

                foreach (var name in names)
                {
                    if (movieOld.ProductionCompanies.Any(e => e.Name == name))
                    {
                        continue;
                    }

                    var entity = existingCompanies.FirstOrDefault(e => e.Name == name);

                    if (entity == null)
                    {
                        entity = new ProductionCompany
                        {
                            Key  = Guid.NewGuid(),
                            Name = name
                        };
                        db.Insert(entity);
                    }

                    db.Insert(new Entity.MovieProductionCompany {
                        MovieKey = movieOld.Key, ProductionCompanyKey = entity.Key
                    });
                }
            }

            if (movieNew.Writers.Any())
            {
                var names           = movieNew.Writers.Select(e => e.FullName);
                var existingWriters = await db.Writers.Where(e => names.Contains(e.FullName)).ToListAsync();

                foreach (var name in names)
                {
                    if (movieOld.Writers.Any(e => e.FullName == name))
                    {
                        continue;
                    }

                    var entity = existingWriters.FirstOrDefault(e => e.FullName == name);

                    if (entity == null)
                    {
                        entity = new Writer
                        {
                            Key      = Guid.NewGuid(),
                            FullName = name
                        };
                        db.Insert(entity);
                    }

                    db.Insert(new Entity.MovieWriter {
                        MovieKey = movieOld.Key, WriterKey = entity.Key
                    });
                }
            }

            await db.Commit();

            return(await Find(movieOld.Key));
        }
        static void Main(string[] args)
        {
            GenreRepository             genreRepository      = new GenreRepository();
            ProductionCompanyRepository companyRepository    = new ProductionCompanyRepository();
            MovieGenreRepository        movieGenreRepository = new MovieGenreRepository();
            MovieRepository             movieRepository      = new MovieRepository();


            Console.WriteLine("Liste des genres disponibles :");
            IEnumerable <Genre> genres = genreRepository.GetAll();

            foreach (Genre g in genres)
            {
                Console.WriteLine($" - {g.Name} (id: {g.Id})");
            }
            Console.WriteLine();

            /*
             * //Console.WriteLine("Ajouter une nouvelle compagnie de production");
             * ProductionCompany company = new ProductionCompany("Lucasfilm");
             * ProductionCompany compDB = companyRepository.Insert(company);
             * Console.WriteLine($" La compagnie \"{compDB.Name}\" a été ajouté avec l'id {compDB.Id}");
             * Console.WriteLine();
             *
             * Console.WriteLine("Liste des compagnies de production :");
             * foreach (ProductionCompany c in companyRepository.GetAll())
             * {
             *  Console.WriteLine($" - {c.Name} (id: {c.Id})");
             * }
             */

            /*
             * Console.WriteLine("Ajouter une nouvelle compagnie de production");
             * Console.WriteLine(" - Movie");
             * long idProdSW4 = companyRepository.GetAll().Single(cp => cp.Name == "Lucasfilm").Id;
             * Movie movie = new Movie(
             *  "Star Wars IV",
             *  "C'est le premier opus de la saga Star Wars par sa date de sortie, mais le quatrième selon l'ordre chronologique de l'histoire. Il est le premier volet de la trilogie originale qui est constituée également des films L'Empire contre-attaque et Le Retour du Jedi. Ce film est aussi le troisième long métrage réalisé par Lucas.",
             *  125,
             *  new DateTime(1977, 10, 19),
             *  idProdSW4
             * );
             *
             * Console.WriteLine(" - Ajout du Genre => Science-fiction");
             * long genreSW4 = genreRepository.Insert(new Genre("Science-fiction")).Id;
             *
             * Console.WriteLine(" - Ajout du film et de son genre");
             * long idSW4 = movieRepository.Insert(movie).Id;
             *
             * movieGenreRepository.Insert(new MovieGenre(idSW4, genreSW4));
             */

            /*
             * long idProdMarmotte = companyRepository.Insert(new ProductionCompany("Columbia Pictures")).Id;
             * long idG1Marmotte = genreRepository.GetAll().Single(g => g.Name == "Comedy").Id;
             * long idG2Marmotte = genreRepository.GetAll().Single(g => g.Name == "Romance").Id;
             * long idG3Marmotte = genreRepository.Insert(new Genre("Fantastic")).Id;
             *
             * Movie marmotte = new Movie(
             *  "Le Jour de la marmotte (VQ)",
             *  null,
             *  101,
             *  null,
             *  idProdMarmotte
             * );
             *
             * long idMarmotte = movieRepository.Insert(marmotte).Id;
             * movieGenreRepository.Insert(new MovieGenre(idMarmotte, idG1Marmotte));
             * movieGenreRepository.Insert(new MovieGenre(idMarmotte, idG2Marmotte));
             * movieGenreRepository.Insert(new MovieGenre(idMarmotte, idG3Marmotte));
             */

            Console.WriteLine("Les films disponibles :");
            IEnumerable <Movie> movies = movieRepository.GetAll();

            foreach (Movie m in movies)
            {
                ProductionCompany pc = companyRepository.Get(m.IdProductionCompany);

                string movieDuration = (m.Duration != null) ? $"{m.Duration} min" : "Unknown";
                string movieRelease  = m.ReleaseDate?.ToString("dd MMM yyyy") ?? "Unknown";

                Console.WriteLine($" - Film : {m.Title}");
                Console.WriteLine($"   Durée : {movieDuration}");
                Console.WriteLine($"   Production : {pc.Name}");
                Console.WriteLine($"   Date de sortie : {movieRelease}");

                Console.WriteLine("   Genres : ");
                IEnumerable <MovieGenre> mgs = movieGenreRepository.GetAll().Where(elem => elem.IdMovie == m.Id);
                foreach (MovieGenre mg in mgs)
                {
                    Genre movieGenre = genreRepository.Get(mg.IdGenre);
                    Console.WriteLine($"    > {movieGenre.Name}");
                }
                Console.WriteLine();
            }


            Console.ReadLine();
        }
 public ProductionCompanyMovie(ProductionCompany productionCompany, Movie movie)
     : this()
 {
     ProductionCompany = productionCompany;
     Movie             = movie;
 }
 public ProductionCompanyMovie(ProductionCompany productionCompany, Movie movie)
     : this()
 {
     ProductionCompany = productionCompany;
     Movie = movie;
 }
示例#29
0
        public async Task <bool> SaveFullInfo(TmdbWrapper.Movies.Movie selectedMovieInfo)
        {
            if (selectedMovieInfo == null)
            {
                return(false);
            }
            //The movie might already exist in the universe so this would replace it
            //This is a search Result for a specific movie
            selectedMovie = u.GetMovie(selectedMovieSummary.Id);
            if (selectedMovie != null)
            {
                if (MessageBox.Show("Replace " + selectedMovie.Title + " with web data?", "Confirm Replace", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return(false);
                }
            }

            //Clear or create
            selectedMovie = new Movie(selectedMovieInfo.Title, selectedMovieInfo.ReleaseDate.Value.Year);
            selectedMovie.BackdropPath  = selectedMovieInfo.BackdropPath;
            selectedMovie.TmdbId        = selectedMovieInfo.Id;
            selectedMovie.ImdbId        = selectedMovieInfo.ImdbId;
            selectedMovie.OriginalTitle = selectedMovieInfo.OriginalTitle;
            selectedMovie.Overview      = selectedMovieInfo.Overview;
            selectedMovie.PosterPath    = selectedMovieInfo.PosterPath;
            selectedMovie.ReleaseDate   = selectedMovieInfo.ReleaseDate;
            selectedMovie.Revenue       = selectedMovieInfo.Revenue;
            selectedMovie.Runtime       = selectedMovieInfo.Runtime;
            selectedMovie.HomePage      = selectedMovieInfo.Homepage;
            //TODO - add remaining properties

            //Add Collection Id to movie ONLY if one exists
            if (selectedMovieInfo.BelongsToCollection != null)
            {
                //Add Collection ID to Movie
                //selectedMovie.CollectionId = selectedMovieInfo.BelongsToCollection.Id;
                MovieCollection mc = u.GetMovieCollection(selectedMovieInfo.Id);
                if (mc == null)
                {
                    //Lookup selectedMovieInfo.BelongsToCollection.Id to see if it exists..
                    //Add Collection to Universe
                    MovieCollection m = u.AddMovieCollection(selectedMovieInfo.BelongsToCollection.Name, selectedMovieInfo.BelongsToCollection.Id, selectedMovieInfo.BelongsToCollection.PosterPath, selectedMovieInfo.BelongsToCollection.BackdropPath);

                    //ONly need to do this once per movie in the collection!!
                    //update the parts of the collection below for Universe
                    TmdbWrapper.Collections.Collection coll = await selectedMovieInfo.BelongsToCollection.CollectionAsync();

                    if (coll != null)
                    {
                        m.Overview = coll.Overview; //Update the Movie Collection Overview.
                        foreach (TmdbWrapper.Collections.Part p in coll.Parts)
                        {
                            u.AddMovieToCollection(m.Id, p.Id); // Add the movie ids of the parts to the Movie Collection Part

                            //m.Parts.Add(p.Id); // Add the movie ids of the parts to the Movie Collection Part
                        }
                    }
                    else
                    {
                        Console.WriteLine("Should never be here! Movie Belongs to a collection but Collection is null!");
                    }
                }
            }


            //Add Production Companies - Already have

            foreach (var item in selectedMovieInfo.ProductionCompanies)
            {
                //Try to get the Production Company and see if it has been updated if Null or not updated then Do web lookup

                ProductionCompany pc = u.GetProductionCompany(item.Id);
                if (u.GetProductionCompany(item.Id) == null || pc.Updated == false)
                {
                    TmdbWrapper.Companies.Company c = await item.CompanyAsync(); // await FindProductionCompany(item.Id);

                    pc              = new ProductionCompany(item.Name, item.Id, item.LogoPath, item.OriginCountry);
                    pc.Description  = c.Description;
                    pc.Headquarters = c.Headquarters;
                    pc.Homepage     = c.Homepage;
                    pc.Updated      = true; // Flag so it will not cause a lookup again.
                                            //Add Parent Production Companies
                    if (c.ParentCompany != null)
                    {
                        pc.ParentCompanyId = c.ParentCompany.Id; // This could change based on movie release data.. (before purchase of A by B)
                    }
                    u.AddProductionCompany(pc);
                }
                MovieProductionCompanyMap mpcm = new MovieProductionCompanyMap();
                mpcm.MovieId             = selectedMovieInfo.Id;
                mpcm.ProductionCompanyId = item.Id;
                u.MovieProductionCompanyMap.Add(mpcm);
            }

            //Get the Movie Credits Now.
            TmdbWrapper.Movies.Credits credits = await selectedMovieInfo.CreditsAsync();

            //credits.Cast
            int  personCount = 0;
            bool skip        = false;
            int  castLimit   = 100;

            foreach (TmdbWrapper.Movies.CastPerson cp in credits.Cast)
            {
                //try
                //{
                String cpCharacter = cp.Character;
                if (cpCharacter.Length == 0)     // Seriously??!!??
                {
                    switch (cp.Gender)
                    {
                    case 0:
                        cpCharacter = "Themself";
                        break;

                    case 1:
                        cpCharacter = "Herself";
                        break;

                    case 2:
                        cpCharacter = "Himself";
                        break;
                    }
                }
                ////Add Character To Movie (Could be Alias able character so mapping would be necessary)
                Character c = u.AddCharacter(cpCharacter,
                                             selectedMovie.TmdbId,
                                             cp.Id,
                                             cp.CreditId,
                                             cp.CastId,
                                             cp.Order
                                             );
                //}
                //catch (Exception err)
                //{

                //}
                //Get full person Info
                //THis is a problem because TMDB will return delay if getting too many at once.
                //Also SERIOUSLY consider only getting the first 10% of the cast - but probably have them already from other movies..
                //Need on demand.
                Person p = new Person(cp.Name);
                p.Id          = cp.Id;
                p.ProfilePath = cp.ProfilePath;
                skip          = false;
                //See if we already have the person in the list
                if (u.People.Select(o => o.Id == cp.Id).Contains(true))
                {
                    //Get the person and see if they have been updated with full information
                    Person testPC = u.People.First(o => o.Id == cp.Id);
                    if (testPC.Updated)
                    {
                        skip = true;
                    }
                }
                if (!skip && personCount < 2)
                {
                    Thread.Sleep(100); // Slow it down..
                    TmdbWrapper.Persons.Person tmdbPerson = await cp.PersonAsync();

                    p.HomePage     = tmdbPerson.Homepage;
                    p.Biography    = tmdbPerson.Biography;
                    p.Birthday     = tmdbPerson.Birthday;
                    p.Deathday     = tmdbPerson.Deathday;
                    p.PlaceOfBirth = tmdbPerson.PlaceOfBirth;
                    p.Updated      = true;
                    personCount++;
                }
                bool personAdded = u.AddPerson(p); // Will fail to add existing person and add basic and updated people.
                if (--castLimit == 0)
                {
                    break;
                }
            }

            ////credits.Crew - Adds significant numbers of People and data Entry
            #region Crew import
            int crewLimit = 10;
            foreach (TmdbWrapper.Movies.CrewPerson crewPerson in credits.Crew)
            {
                u.AddCrewMember(crewPerson, selectedMovie);
                if (--crewLimit == 0)
                {
                    break;
                }
            }
            #endregion

            //Want this for movie search results..
            TmdbWrapper.Movies.Trailers t = await selectedMovieInfo.TrailersAsync(); // Want to have.. does nothing now..

            if (t != null && t.Youtube.Count > 0)
            {
                String firstSource = t.Youtube[0].Source;
                //https://www.youtube.com/watch?v=CmRih_VtVAs // Example of how to use the source.
                selectedMovie.TrailerLink = "https://www.youtube.com/watch?v=" + firstSource;
            }


            u.AddMovie(selectedMovie);
            //Verify This is OK...
            PersistenceBase.Save(PrivateData.GetRelativePath(@"\Cache\uinverse3.json"), u);
            return(true);
        }