Пример #1
0
        public static void Initialize(CinemaContext context, UserManager <Employee> userManager, string posterDirectory)
        {
            if (context.Movies.Any())
            {
                return;
            }

            var yourName = new Movie()
            {
                Title       = "Your Name",
                Director    = "Makoto Shinkai",
                Length      = new TimeSpan(1, 46, 0),
                Description =
                    "Mitsuha Miyamizu, a high school girl, yearns to live the life of a boy in the bustling city of " +
                    "Tokyo—a dream that stands in stark contrast to her present life in the countryside. Meanwhile in the city, " +
                    "Taki Tachibana lives a busy life as a high school student while juggling his part-time job and " +
                    "hopes for a future in architecture. One day, Mitsuha awakens in a room that is not her own " +
                    "and suddenly finds herself living the dream life in Tokyo—but in Taki's body! " +
                    "Elsewhere, Taki finds himself living Mitsuha's life in the humble countryside.In pursuit of " +
                    "an answer to this strange phenomenon, they begin to search for one another."
            };
            var yugioh = new Movie()
            {
                Title       = "YuGiOh - Dark Side of Dimensions",
                Director    = "Satoshi Kuwabara",
                Length      = new TimeSpan(2, 10, 0),
                Description =
                    "Set six months after the events of the original Yu-Gi-Oh! manga, Yuugi Mutou and his friends are in their " +
                    "final year of high school and are talking about what they will do in the future. " +
                    "Meanwhile, Seto Kaiba has commissioned an excavation to retrieve the disassembled Millennium " +
                    "Puzzle from the ruins of the \"Shrine of the Underworld.\" The item had previously housed " +
                    "the soul of his rival, Atem, whom he hopes to revive in order to settle their score. " +
                    "The excavation is interrupted by a mysterious man, who faces Kaiba in a game of " +
                    "\"Magic & Wizards\" and steals two pieces of the recovered Puzzle. What is his ulterior motive?"
            };
            var eva = new Movie()
            {
                Title       = "The End of Evangelion",
                Director    = "Hideaki Anno",
                Length      = new TimeSpan(1, 27, 0),
                Description =
                    "With the final Angel vanquished, Nerv has one last enemy left to face—the humans under Seele's command." +
                    "Left in a deep depression nearing the end of the original series, an indecisive Shinji Ikari struggles with the ultimatum presented " +
                    "to him: to completely accept mankind's existence, or renounce humanity's individuality. Meanwhile, at the core of a compromised " +
                    "Nerv, Gendou Ikari and Rei Ayanami approach Lilith in an attempt to realize their own ideals concerning the future of the world."
            };
            var lovelive = new Movie()
            {
                Title       = "Love Live! The School Idol Movie",
                Director    = "Kyogoku Takahiko",
                Length      = new TimeSpan(1, 42, 0),
                Description =
                    "Hot on the heels of the third year students' graduation, μ's is invited to New York in hopes of spreading the joy of school idols to other parts of the world. " +
                    "Due to the events of the recent Love Live!, μ's has reached eminent stardom which results in crowds swarming them whenever they appear in public. " +
                    "With the increased attention, however, comes a difficult choice."
            };

            var nogamenolife = new Movie()
            {
                Title       = "No Game No Life Zero",
                Director    = "Atsuko Ishizuka",
                Length      = new TimeSpan(1, 46, 0),
                Description =
                    "In ancient Disboard, Riku is an angry, young warrior intent on saving humanity from the warring Exceed, " +
                    "the sixteen sentient species, fighting to establish the \"One True God\" amongst the Old Deus. " +
                    "In a lawless land, humanity's lack of magic and weak bodies have made them easy targets for the other Exceed, " +
                    "leaving the humans on the brink of extinction. One day, however, hope returns to humanity " +
                    "when Riku finds a powerful female Ex-machina, whom he names Schwi, in an abandoned elf city. " +
                    "Exiled from her Cluster because of her research into human emotions, Schwi is convinced that " +
                    "humanity has only survived due to the power of these feelings and is determined to understand " +
                    "the human heart. Forming an unlikely partnership in the midst of the overwhelming chaos, " +
                    "Riku and Schwi must now find the answers to their individual shortcomings in each other, " +
                    "and discover for themselves what it truly means to be human as they fight for their lives " +
                    "together against all odds. Each with a powerful new ally in tow, it is now up to them to " +
                    "prevent the extinction of the human race and establish peace throughout Disboard!"
            };

            // Add movies to db
            context.Movies.Add(yourName);
            context.Movies.Add(yugioh);
            context.Movies.Add(eva);
            context.Movies.Add(lovelive);
            context.Movies.Add(nogamenolife);

            //create rooms
            var mikuRoom = new Room()
            {
                RoomName  = "Room Miku",
                NumOfCols = 15,
                NumOfRows = 8
            };

            var nicoRoom = new Room()
            {
                RoomName  = "Room Nico",
                NumOfCols = 17,
                NumOfRows = 9
            };

            var aquaRoom = new Room()
            {
                RoomName  = "Room Aqua",
                NumOfCols = 14,
                NumOfRows = 5
            };

            var poiRoom = new Room()
            {
                RoomName  = "Room Poi",
                NumOfCols = 20,
                NumOfRows = 11
            };

            context.Rooms.Add(mikuRoom);
            context.Rooms.Add(nicoRoom);
            context.Rooms.Add(aquaRoom);
            context.Rooms.Add(poiRoom);

            // Create shows
            var programs = new List <Show>()
            {
                new Show()
                {
                    Movie     = nogamenolife,
                    Room      = mikuRoom,
                    StartTime = DateTime.Parse("2019-06-20 18:30:00")
                },
                new Show()
                {
                    Movie     = nogamenolife,
                    Room      = nicoRoom,
                    StartTime = DateTime.Parse("2019-06-24 11:00:00")
                },
                new Show()
                {
                    Movie     = nogamenolife,
                    Room      = poiRoom,
                    StartTime = DateTime.Parse("2019-07-02 15:45:00")
                },
                new Show()
                {
                    Movie     = lovelive,
                    Room      = poiRoom,
                    StartTime = DateTime.Parse("2019-06-21 13:30:00")
                },
                new Show()
                {
                    Movie     = lovelive,
                    Room      = nicoRoom,
                    StartTime = DateTime.Parse("2019-07-26 11:45:00")
                },
                new Show()
                {
                    Movie     = lovelive,
                    Room      = aquaRoom,
                    StartTime = DateTime.Parse("2019-07-04 16:45:00")
                },
                new Show()
                {
                    Movie     = yourName,
                    Room      = aquaRoom,
                    StartTime = DateTime.Parse("2019-06-20 20:30:00")
                },
                new Show()
                {
                    Movie     = yourName,
                    Room      = nicoRoom,
                    StartTime = DateTime.Parse("2019-06-30 14:00:00")
                },
                new Show()
                {
                    Movie     = yourName,
                    Room      = mikuRoom,
                    StartTime = DateTime.Parse("2019-07-06 08:30:00")
                },
                new Show()
                {
                    Movie     = eva,
                    Room      = poiRoom,
                    StartTime = DateTime.Parse("2019-06-20 17:45:00")
                },
                new Show()
                {
                    Movie     = eva,
                    Room      = mikuRoom,
                    StartTime = DateTime.Parse("2019-06-30 12:15:00")
                },
                new Show()
                {
                    Movie     = eva,
                    Room      = aquaRoom,
                    StartTime = DateTime.Parse("2019-07-08 15:30:00")
                },
                new Show()
                {
                    Movie     = yugioh,
                    Room      = mikuRoom,
                    StartTime = DateTime.Parse("2019-06-23 18:15:00")
                },
                new Show()
                {
                    Movie     = yugioh,
                    Room      = nicoRoom,
                    StartTime = DateTime.Parse("2019-06-27 14:00:00")
                },
                new Show()
                {
                    Movie     = yugioh,
                    Room      = poiRoom,
                    StartTime = DateTime.Parse("2019-07-04 15:15:00")
                }
            };

            foreach (var prog in programs)
            {
                for (int i = 0; i < prog.Room.NumOfRows; i++)
                {
                    for (int j = 0; j < prog.Room.NumOfCols; j++)
                    {
                        context.Seats.Add(
                            new Seat()
                        {
                            Row   = i,
                            Col   = j,
                            Room  = prog.Room,
                            Show  = prog,
                            State = State.Free
                        });
                    }
                }

                context.Shows.Add(prog);
            }

            if (Directory.Exists(posterDirectory))
            {
                var images = new List <Poster>();
                if (File.Exists(Path.Combine(posterDirectory, "EndOfEva.png")))
                {
                    images.Add(new Poster
                    {
                        Movie = eva,
                        Image = File.ReadAllBytes(Path.Combine(posterDirectory, "EndOfEva.png"))
                    });
                }
                if (File.Exists(Path.Combine(posterDirectory, "LL.png")))
                {
                    images.Add(new Poster
                    {
                        Movie = lovelive,
                        Image = File.ReadAllBytes(Path.Combine(posterDirectory, "LL.png"))
                    });
                }
                if (File.Exists(Path.Combine(posterDirectory, "NGNLZ.png")))
                {
                    images.Add(new Poster
                    {
                        Movie = nogamenolife,
                        Image = File.ReadAllBytes(Path.Combine(posterDirectory, "NGNLZ.png"))
                    });
                }
                if (File.Exists(Path.Combine(posterDirectory, "YourName.png")))
                {
                    images.Add(new Poster
                    {
                        Movie = yourName,
                        Image = File.ReadAllBytes(Path.Combine(posterDirectory, "YourName.png"))
                    });
                }
                if (File.Exists(Path.Combine(posterDirectory, "YuGiOh.png")))
                {
                    images.Add(new Poster
                    {
                        Movie = yugioh,
                        Image = File.ReadAllBytes(Path.Combine(posterDirectory, "YuGiOh.png"))
                    });
                }

                foreach (var image in images)
                {
                    context.Posters.Add(image);
                }
            }

            if (userManager != null)
            {
                var adminUser = new Employee()
                {
                    UserName    = "******",
                    FullName    = "Dolgozo1",
                    Email       = "*****@*****.**",
                    PhoneNumber = "+36123456789"
                };
                var adminPassword = "******";

                var result1 = userManager.CreateAsync(adminUser, adminPassword).Result;
            }

            context.SaveChanges();
        }
        public static void Initialize(IServiceProvider serviceProvider, string imageDirectory)
        {
            CinemaContext context = serviceProvider.GetRequiredService <CinemaContext>();

            _userManager = serviceProvider.GetRequiredService <UserManager <Employee> >();

            /*
             * Adatbázis létrehozása (amennyiben nem létezik), illetve a migrációk alapján a frissítése.
             * Amennyiben teljesen el szeretnénk vetni a jelenlegi adatbázisunk, akkor a
             * törléshez az Sql Server Object Explorer ablak használható a Visual Studioban.
             * Itt SQL Server > (localdb)\\MSSQLLocalDB útvonalon találjuk az adatbázisainkat.
             */
            //context.Database.EnsureDeleted();
            context.Database.Migrate();

            // Listák keresése
            if (context.Screenings.Any())
            {
                return; // Az adatbázis már inicializálva van.
            }

            _userManager.CreateAsync(new Employee
            {
                UserName = "******",
                RealName = "Gonda David"
            }, "Admin12345");

            var bladerunnerPath = Path.Combine(imageDirectory, "blade_runner_2049.jpg");
            var gbphPath        = Path.Combine(imageDirectory, "grand_budapest_hotel.jpg");
            var swrosPath       = Path.Combine(imageDirectory, "sw9.jpg");
            var alienPath       = Path.Combine(imageDirectory, "alien.jpg");
            var scottpPath      = Path.Combine(imageDirectory, "scottp.jpg");
            var midsPath        = Path.Combine(imageDirectory, "midsommar.jpg");

            IList <Movie>     defaultMovies     = new List <Movie>();
            IList <Room>      defaultRooms      = new List <Room>();
            IList <Screening> defaultScreenings = new List <Screening>();

            defaultMovies.Add(new Movie
            {
                Name            = "Blade Runner 2049",
                Director        = "Denis Villeneuve",
                Synopsis        = "Young Blade Runner K's discovery of a long-buried secret leads him to track down former Blade Runner Rick Deckard, who's been missing for thirty years.",
                LengthInMinutes = 163,
                Image           = File.Exists(bladerunnerPath) ? File.ReadAllBytes(bladerunnerPath) : null,
                PostTime        = DateTime.Now
            });

            defaultMovies.Add(new Movie
            {
                Name            = "The Grand Budapest Hotel",
                Director        = "Wes Anderson",
                Synopsis        = "A writer encounters the owner of an aging high-class hotel, who tells him of his early years serving as a lobby boy in the hotel's glorious years under an exceptional concierge.",
                LengthInMinutes = 100,
                Image           = File.Exists(gbphPath) ? File.ReadAllBytes(gbphPath) : null,
                PostTime        = DateTime.Now
            });

            defaultMovies.Add(new Movie
            {
                Name            = "Star Wars: Episode IX - The Rise of Skywalker",
                Director        = "J.J. Abrams",
                Synopsis        = "The surviving members of the resistance face the First Order once again, and the legendary conflict between the Jedi and the Sith reaches its peak bringing the Skywalker saga to its end.",
                LengthInMinutes = 142,
                Image           = File.Exists(swrosPath) ? File.ReadAllBytes(swrosPath) : null,
                PostTime        = DateTime.Now
            });

            defaultMovies.Add(new Movie
            {
                Name            = "Alien",
                Director        = "Ridley Scott",
                Synopsis        = "After a space merchant vessel receives an unknown transmission as a distress call, one of the crew is attacked by a mysterious life form and they soon realize that its life cycle has merely begun.",
                LengthInMinutes = 117,
                Image           = File.Exists(alienPath) ? File.ReadAllBytes(alienPath) : null,
                PostTime        = DateTime.Now
            });

            defaultMovies.Add(new Movie
            {
                Name            = "Scott Pilgrim vs. the World",
                Director        = "Edgar Wright",
                Synopsis        = "Scott Pilgrim must defeat his new girlfriend's seven evil exes in order to win her heart.",
                LengthInMinutes = 112,
                Image           = File.Exists(scottpPath) ? File.ReadAllBytes(scottpPath) : null,
                PostTime        = DateTime.Now
            });

            defaultMovies.Add(new Movie
            {
                Name            = "Midsommar",
                Director        = "Ari Aster",
                Synopsis        = "A couple travels to Sweden to visit a rural hometown's fabled mid-summer festival. What begins as an idyllic retreat quickly devolves into an increasingly violent and bizarre competition at the hands of a pagan cult.",
                LengthInMinutes = 148,
                Image           = File.Exists(midsPath) ? File.ReadAllBytes(midsPath) : null,
                PostTime        = DateTime.Now
            });

            foreach (Movie movie in defaultMovies)
            {
                context.Movies.Add(movie);
            }

            defaultRooms.Add(new Room
            {
                Name    = "Room Dave",
                Rows    = 10,
                Columns = 10
            });

            defaultRooms.Add(new Room
            {
                Name    = "Room Alexa",
                Rows    = 5,
                Columns = 10
            });

            defaultRooms.Add(new Room
            {
                Name    = "Room Geralt",
                Rows    = 10,
                Columns = 5
            });

            foreach (Room room in defaultRooms)
            {
                context.Rooms.Add(room);
            }

            context.SaveChanges();

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Blade Runner 2049").Id,
                StartTime = new DateTime(2020, 10, 11, 16, 00, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Geralt").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Star Wars: Episode IX - The Rise of Skywalker").Id,
                StartTime = new DateTime(2020, 10, 11, 16, 00, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Dave").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Blade Runner 2049").Id,
                StartTime = new DateTime(2020, 10, 11, 20, 00, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Dave").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Blade Runner 2049").Id,
                StartTime = new DateTime(2020, 11, 16, 20, 00, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Geralt").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "The Grand Budapest Hotel").Id,
                StartTime = new DateTime(2020, 10, 12, 12, 00, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Dave").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Alien").Id,
                StartTime = new DateTime(2020, 10, 09, 09, 30, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Geralt").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Scott Pilgrim vs. the World").Id,
                StartTime = new DateTime(2020, 09, 15, 16, 00, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Alexa").Id
            });

            defaultScreenings.Add(new Screening
            {
                MovieId   = context.Movies.FirstOrDefault(i => i.Name == "Midsommar").Id,
                StartTime = new DateTime(2020, 10, 11, 15, 30, 00),
                RoomId    = context.Rooms.FirstOrDefault(i => i.Name == "Room Alexa").Id
            });

            foreach (Screening screening in defaultScreenings)
            {
                context.Screenings.Add(screening);
            }

            context.SaveChanges();
        }