예제 #1
0
        public async Task AddMovie(int id)
        {
            try
            {
                var movie = await Client.GetMovieAsync(id, MovieMethods.Credits);

                string date;

                if (movie.ReleaseDate == null)
                {
                    date = "No info available";
                }
                else
                {
                    date = ((DateTime)movie.ReleaseDate).ToString("dd.MM.yyyy");
                }

                string image = "no_poster.jpg";

                if (Settings.Instance.DownloadImages)
                {
                    image = Client.GetImageUrl("w500", movie.PosterPath).ToString();
                }

                Film film = new Film(movie.Title, (short)movie.Runtime, date, movie.Overview, image);

                foreach (var actor in movie.Credits.Cast)
                {
                    string name = actor.Name;
                    foreach (var existingActor in ActorCollection.Instance.Actors.Where(a => a.Name == name))
                    {
                        film.AddActor(existingActor);
                    }
                }

                foreach (var producer in movie.Credits.Crew)
                {
                    string name = producer.Name;
                    foreach (var existingProducer in ProducerCollection.Instance.Producers.Where
                                 (p => p.Name == name && producer.Job == "Director"))
                    {
                        film.AddProducer(existingProducer);
                    }
                }

                foreach (var genre in movie.Genres)
                {
                    foreach (var g in Enum.GetValues(typeof(Genres)))
                    {
                        if (((Genres)g).ToString() == genre.Name.Replace(" ", ""))
                        {
                            film.GenresList.Add((Genres)g);
                        }
                    }
                }

                FilmCollection.Instance.Films.Add(film);
                UserDialogs.Instance.Toast("Success!");
            }
            catch (HttpRequestException)
            {
                UserDialogs.Instance.Toast("Network Error");
            }
            catch (Exception)
            {
                UserDialogs.Instance.Toast("Ooops! Something went wrong!");
            }
        }
        public static void CopyToData(this FilmInput input, Film data, HttpPostedFileBase poster,
                                      IDaoCountry daoCountry, IDaoGenre daoGenre, IDaoDirector daoDirector, IDaoActor daoActor)
        {
            if (data.ID != input.ID)
            {
                throw new Exception("Cannot copy from foreign view to data");
            }

            data.Title       = input.Title;
            data.ReleaseDate = input.ReleaseDate;
            data.IMDbRating  = input.IMDbRating;
            data.Duration    = input.Duration;
            data.Description = input.Description;
            data.Countries   = new List <Country>();

            foreach (var name in input.Countries)
            {
                data.Countries.Add(daoCountry.GetCountryByEnglishName(name));
            }

            data.RemoveAllGenres();

            if (input.Genres != null)
            {
                foreach (var id in input.Genres)
                {
                    var genre = daoGenre.Find(id);
                    data.AddGenre(genre);
                }
            }

            if (input.DirectorID != Guid.Empty)
            {
                data.Director = daoDirector.Find(input.DirectorID);
            }

            data.RemoveAllActors();
            if (input.Actors != null)
            {
                foreach (var id in input.Actors)
                {
                    var actor = daoActor.Find(id);

                    data.AddActor(actor);
                }
            }

            if (poster != null && poster.ContentLength > 0)
            {
                try
                {
                    if (poster.ContentType.Contains("image"))
                    {
                        var filename = Guid.NewGuid().ToString() + Path.GetExtension(poster.FileName);

                        var path = Path.Combine(PathUtils.GetProjectDirectory(),
                                                "Cinematheque.WebSite\\images\\films\\",
                                                filename);
                        poster.SaveAs(path);

                        /*File.Delete(Path.Combine(PathUtils.GetProjectDirectory(),
                         *                      "Cinematheque.WebSite\\images\\films\\",
                         *                      filename);*/

                        data.PosterFileName = filename;
                    }
                    else
                    {
                        throw new Exception("ERROR: Uploaded file is not image");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("ERROR:" + ex.Message.ToString());
                }
            }
        }
        public static Film CreateFilm(this FilmInput input, HttpPostedFileBase poster,
                                      IDaoCountry daoCountry, IDaoActor daoActor, IDaoDirector daoDirector, IDaoGenre daoGenre)
        {
            var film = new Film
            {
                Title       = input.Title,
                ReleaseDate = input.ReleaseDate,
                IMDbRating  = input.IMDbRating,
                Duration    = input.Duration,
                Description = input.Description,
                Countries   = new List <Country>()
            };

            foreach (var name in input.Countries)
            {
                film.Countries.Add(daoCountry.GetCountryByEnglishName(name));
            }

            if (poster != null && poster.ContentLength > 0)
            {
                try
                {
                    if (poster.ContentType.Contains("image"))
                    {
                        var filename = Guid.NewGuid().ToString() + Path.GetExtension(poster.FileName);

                        var path = Path.Combine(PathUtils.GetProjectDirectory(),
                                                "Cinematheque.WebSite\\images\\films\\",
                                                filename);
                        poster.SaveAs(path);

                        film.PosterFileName = filename;
                    }
                    else
                    {
                        throw new Exception("ERROR: Uploaded file is not image");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("ERROR:" + ex.Message.ToString());
                }
            }
            else
            {
                film.PosterFileName = "default.jpg";
            }

            if (input.Genres != null)
            {
                foreach (var id in input.Genres)
                {
                    var genre = daoGenre.Find(id);
                    film.AddGenre(genre);
                }
            }

            film.Director = daoDirector.Find(input.DirectorID);

            if (input.Actors != null)
            {
                foreach (var id in input.Actors)
                {
                    var actor = daoActor.Find(id);

                    film.AddActor(actor);
                }
            }

            return(film);
        }
        protected override void Seed(CinemathequeContext context)
        {
            foreach (var n in CountryList.EnglishNames)
            {
                context.Countries.Add(new Country {
                    Name = n
                });
            }
            context.SaveChanges();

            var country = context.Countries.Where(c => c.Name == "France").FirstOrDefault();

            for (var i = 0; i < 10; i++)
            {
                var ch = Convert.ToChar(65 + i);

                var a = new Actor()
                {
                    Name          = ch.ToString() + "aaak",
                    Surname       = "Actor",
                    Birth         = DateTime.Now,
                    CountryId     = country.ID,
                    Gender        = Gender.NotIdentified,
                    PhotoFileName = $"actor{ch}.jpg",
                    Biography     = "aaaaaaaaaaaaaaaaaaaaaaa"
                };

                var d = new Director()
                {
                    Name          = ch.ToString(),
                    Surname       = "Director",
                    Birth         = DateTime.Now,
                    CountryId     = country.ID,
                    Gender        = Gender.NotIdentified,
                    PhotoFileName = $"director{ch}.jpg",
                    Biography     = "ddddddddddddddddddddddddd"
                };

                var f = new Film()
                {
                    Title          = $"film{ch}",
                    ReleaseDate    = DateTime.Now,
                    Countries      = new List <Country>(),
                    IMDbRating     = 5,
                    Description    = "fffffffffffffffffffff",
                    PosterFileName = $"film{ch}.jpg",
                    Duration       = TimeSpan.FromMinutes(90)
                };
                f.Countries.Add(country);

                var g = new Genre()
                {
                    Name = $"Genre {ch}"
                };

                a.AddFilm(f);
                f.AddActor(a);
                f.AddGenre(g);
                g.AddFilm(f);
                d.AddFilm(f);
                f.DirectorID = d.ID;

                context.Films.Add(f);
                context.Actors.Add(a);
                context.Genres.Add(g);
                context.Directors.Add(d);
            }

            context.SaveChanges();
            base.Seed(context);
        }
예제 #5
0
        private static void FillContainer(IUnityContainer container)
        {
            var daoDirector = container.Resolve <IDaoDirector>();
            var daoActor    = container.Resolve <IDaoActor>();
            var daoFilm     = container.Resolve <IDaoFilm>();
            var daoGenre    = container.Resolve <IDaoGenre>();
            var daoCountry  = container.Resolve <IDaoCountry>();

            var country = daoCountry.GetCountryByEnglishName("France");

            for (var i = 0; i < 10; i++)
            {
                var ch = Convert.ToChar(65 + i);

                var a = new Actor()
                {
                    Name          = ch.ToString() + "aaak",
                    Surname       = "Actor",
                    Birth         = DateTime.Now,
                    CountryId     = country.ID,
                    Gender        = Gender.NotIdentified,
                    PhotoFileName = $"actor{ch}.jpg",
                    Biography     = "aaaaaaaaaaaaaaaaaaaaaaa"
                };

                var d = new Director()
                {
                    Name          = ch.ToString(),
                    Surname       = "Director",
                    Birth         = DateTime.Now,
                    CountryId     = country.ID,
                    Gender        = Gender.NotIdentified,
                    PhotoFileName = $"director{ch}.jpg",
                    Biography     = "ddddddddddddddddddddddddd"
                };

                var f = new Film()
                {
                    Title          = $"film{ch}",
                    ReleaseDate    = DateTime.Now,
                    Countries      = new List <Country>(),
                    IMDbRating     = 5,
                    Description    = "fffffffffffffffffffff",
                    PosterFileName = $"film{ch}.jpg",
                    Duration       = TimeSpan.FromMinutes(90)
                };
                f.Countries.Add(country);

                var g = new Genre()
                {
                    Name = $"Genre {ch}"
                };

                a.AddFilm(f);
                f.AddActor(a);
                f.AddGenre(g);
                g.AddFilm(f);
                d.AddFilm(f);
                f.DirectorID = d.ID;

                daoFilm.Add(f);
                daoActor.Add(a);
                daoGenre.Add(g);
                daoDirector.Add(d);
            }
        }