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());
                }
            }
        }
示例#2
0
        public static void AddNewCassette()
        {
            Cassette cassette = Cassette.ReadData();

            // Добавление фильмов
            using (var unit = new ClassUnitOfWorkRep(new MineVideoRental()))
            {
                // если с таким названием кассетта уже есть
                if (unit.CassetteRepasitory.IsCassetteExists(cassette))
                {
                    Console.WriteLine("Ничего нового - такая кассетта уже есть");
                    Console.ReadLine();
                    unit.Dispose();
                    return; // то просто выходим из метода
                }

                bool enough   = false;
                bool onceMore = true;
                Console.WriteLine("Добавить фильмы:");
                do
                {
                    string answerString;
                    int    answer = 0;

                    Film film = Film.ReadData();
                    if (unit.FilmRepasitory.IsFilmExists(film))       // если такой фильм уже есть
                    {
                        film     = unit.FilmRepasitory.GetSame(film); // то берем его из базы
                        onceMore = false;                             // еще жанры к фильму не будем добавлять
                    }
                    else
                    {
                        Genre genre = Genre.ReadData();
                        if (unit.GenreRepasitory.IsGenreExists(genre))   // если такой жанр уже есть
                        {
                            genre = unit.GenreRepasitory.GetSame(genre); // то берем его из базы
                        }
                        else
                        {
                            unit.GenreRepasitory.Add(genre);
                        }

                        film.AddGenre(genre);
                        unit.FilmRepasitory.Add(film);
                        onceMore = true;
                    }

                    while (onceMore)
                    {
                        Console.Write("Добавить еще жанр к фильму? (0 - нет, 1 - да) ");
                        answerString = Console.ReadLine();

                        if (int.TryParse(answerString, out answer))
                        {
                            if (answer != 0)
                            {
                                Genre genre = Genre.ReadData();
                                if (unit.GenreRepasitory.IsGenreExists(genre))
                                {
                                    genre = unit.GenreRepasitory.GetSame(genre);
                                }
                                else
                                {
                                    unit.GenreRepasitory.Add(genre);
                                }
                                // update
                                film.AddGenre(genre);
                            }
                            else
                            {
                                onceMore = false;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Что-то пошло не так... Ничего не будем добавлять");
                            onceMore = false;
                        }
                    }

                    cassette.AddFilm(film);

                    Console.Write("Добавить еще фильм? (0 - нет, 1 - да) ");
                    answerString = Console.ReadLine();
                    answer       = 0;
                    if (int.TryParse(answerString, out answer))
                    {
                        if (answer == 0)
                        {
                            enough = true;
                        }
                    }
                } while (!enough);

                unit.CassetteRepasitory.Add(cassette);
                unit.save();
            }
        }
        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);
        }
        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);
        }
示例#5
0
        static void Main(string[] args)
        {
            var comedy = new Genre {
                Type = "Комедия"
            };
            var drama = new Genre {
                Type = "Драма"
            };
            var melodrama = new Genre {
                Type = "Мелодрама"
            };
            var military = new Genre {
                Type = "Военный"
            };
            var musical = new Genre {
                Type = "Мюзикл"
            };
            var fantasy = new Genre {
                Type = "Фэнтези"
            };

            var Devchata = new Film {
                Title = "Девчата", Year = 1962
            };

            Devchata.AddGenre(comedy);
            Devchata.AddGenre(melodrama);

            var Casablanca = new Film {
                Title = "Касабланка", Year = 1942
            };

            Casablanca.AddGenre(drama);
            Casablanca.AddGenre(melodrama);
            Casablanca.AddGenre(military);

            var SleepingBeauty = new Film {
                Title = "Спящая красавица", Year = 1958
            };

            SleepingBeauty.AddGenre(musical);
            SleepingBeauty.AddGenre(melodrama);
            SleepingBeauty.AddGenre(fantasy);

            Cassette cassette1 = new Cassette {
                Amount = 1, Title = "Странное собрание"
            };

            cassette1.AddFilm(Casablanca);
            cassette1.AddFilm(Devchata);

            Cassette cassette4 = new Cassette {
                Amount = 4, Title = "Коллекция Disney. Спящая красавица"
            };

            cassette4.AddFilm(SleepingBeauty);

            var client = new Client {
                Name = new Name("Таня", "Тугодубодумова")
            };

            var order1 = new Order {
                OrderStart = new DateTime(2019, 1, 14), OrderFinish = new DateTime(2019, 1, 18)
            };

            order1.AddCassette(cassette1);

            var order2 = new Order {
                OrderStart = new DateTime(2019, 1, 19), OrderFinish = new DateTime(2019, 1, 26)
            };

            order2.AddCassette(cassette4);

            client.AddOrder(order1);
            client.AddOrder(order2);

            order1.Close(new DateTime(2019, 1, 19));
            order2.Close(new DateTime(2019, 1, 20));



            using (ClassUnitOfWorkRep unit = new ClassUnitOfWorkRep(new MineVideoRental()))
            {
                unit.GenreRepasitory.Add(comedy);
                unit.GenreRepasitory.Add(drama);
                unit.GenreRepasitory.Add(melodrama);
                unit.GenreRepasitory.Add(military);
                unit.GenreRepasitory.Add(musical);
                unit.GenreRepasitory.Add(fantasy);

                unit.FilmRepasitory.Add(Devchata);
                unit.FilmRepasitory.Add(Casablanca);
                unit.FilmRepasitory.Add(SleepingBeauty);

                unit.CassetteRepasitory.Add(cassette1);
                unit.CassetteRepasitory.Add(cassette4);

                unit.ClientRepasitory.Add(client);

                unit.OrderRepasitory.Add(order1);
                unit.OrderRepasitory.Add(order2);

                unit.save();

                IList <Cassette> allCassettes = unit.CassetteRepasitory.GetAll().ToList();

                Console.WriteLine("All cassettes:");
                foreach (var cassette in allCassettes)
                {
                    Console.WriteLine($"Cassette id={cassette.cassetteID}, amount={cassette.Amount}");
                }

                IList <Cassette> minCassettes = unit.CassetteRepasitory.GetCassetteMin(3).ToList();
                Console.WriteLine("Cassettes which have amount < 3 :");
                foreach (var cassette in minCassettes)
                {
                    Console.WriteLine($"Cassette id={cassette.cassetteID}, amount={cassette.Amount}");
                }

                IList <Cassette> maxCassettes = unit.CassetteRepasitory.GetCassetteMax(3).ToList();
                Console.WriteLine("Cassettes which have amount >= 3 :");
                foreach (var cassette in maxCassettes)
                {
                    Console.WriteLine($"Cassette id={cassette.cassetteID}, amount={cassette.Amount}");
                }

                // var film = unit.FilmRepasitory.GetFilm("Девчата");
                // var genres = unit.GenreRepasitory.GetFilmGenres(film);

                // Console.WriteLine($"Genres of film {film.Title}:");
                //foreach (var g in genres)
                //  Console.WriteLine(g.Type);



                IList <Cassette> allcassettes = unit.CassetteRepasitory.GetAll().ToList();
                foreach (var cassette in allcassettes)
                {
                    Console.WriteLine($"Cassette ID={cassette.cassetteID}, amount={cassette.Amount}");
                }


                IList <Cassette> mincassettes = unit.CassetteRepasitory.GetCassetteMin(3).ToList();
                foreach (var mincassette in mincassettes)
                {
                    Console.WriteLine($"Min Cassette ={mincassette.cassetteID}, amount={mincassette.Amount}");
                }

                IList <Cassette> maxcassettes = unit.CassetteRepasitory.GetCassetteMax(55).ToList();
                foreach (var maxcassette in maxcassettes)
                {
                    Console.WriteLine($"Max Cassette ={maxcassette.cassetteID}, amount={maxcassette.Amount}");
                }
            }
        }
示例#6
0
        public static IEnumerable <Film> SeedData()
        {
            Genre drama = new Genre
            {
                Title = "drama"
            };

            Genre action = new Genre
            {
                Title = "action"
            };

            Genre comedy = new Genre
            {
                Title = "comedy"
            };

            Genre fantasy = new Genre
            {
                Title = "fantasy"
            };

            Genre sf = new Genre
            {
                Title = "sci-fi"
            };

            Genre thriller = new Genre
            {
                Title = "thriller"
            };

            Genre horror = new Genre
            {
                Title = "horror"
            };

            Film f1 = new Film
            {
                Title = "Fight Club",
                Year  = 1999
            };

            Film f2 = new Film
            {
                Title = "The Dark Knight",
                Year  = 2008
            };

            Film f3 = new Film
            {
                Title = "Star Wars: Episode V - The Empire Strikes Back",
                Year  = 1980
            };

            Film f4 = new Film
            {
                Title = "Alien",
                Year  = 1979
            };

            Film f5 = new Film
            {
                Title = "Trainspotting",
                Year  = 1996
            };

            // ----
            f1.AddGenre(drama);
            f1.AddGenre(action);
            f1.AddGenre(thriller);
            yield return(f1);

            f2.AddGenre(drama);
            f2.AddGenre(action);
            f2.AddGenre(fantasy);
            yield return(f2);

            f3.AddGenre(drama);
            f3.AddGenre(action);
            f3.AddGenre(fantasy);
            f3.AddGenre(sf);
            yield return(f3);

            f4.AddGenre(drama);
            f4.AddGenre(action);
            f4.AddGenre(horror);
            f4.AddGenre(sf);
            f4.AddGenre(thriller);
            yield return(f4);

            f5.AddGenre(drama);
            f5.AddGenre(action);
            f5.AddGenre(comedy);
            yield return(f5);
        }
示例#7
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);
            }
        }