Beispiel #1
0
        private void InitializeDatabase()
        {
            var options = new DbContextOptionsBuilder <CinemaWorldDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            this.dbContext = new CinemaWorldDbContext(options);
        }
        public async Task SeedAsync(CinemaWorldDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(ApplicationDbContextSeeder));

            var seeders = new List <ISeeder>
            {
                new RolesSeeder(),
                new DirectorsSeeder(),
                new SeatsSeeder(new Random()),
            };

            foreach (var seeder in seeders)
            {
                await seeder.SeedAsync(dbContext, serviceProvider);

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
        public async Task SeedAsync(CinemaWorldDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.Directors.Any())
            {
                return;
            }

            var directors = new List <(string FirstName, string LastName)>
            {
                ("Steven", "Spielberg"),
                ("Martin", "Scorsese"),
                ("Quentin", "Tarantino"),
                ("James", "Cameron"),
                ("Woody", "Allen"),
            };

            foreach (var director in directors)
            {
                await dbContext.Directors.AddAsync(new Director
                {
                    FirstName = director.FirstName,
                    LastName  = director.LastName,
                });
            }
        }
        public async Task SeedAsync(CinemaWorldDbContext dbContext, IServiceProvider serviceProvider)
        {
            var roleManager = serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >();

            await SeedRoleAsync(roleManager, GlobalConstants.AdministratorRoleName);
            await SeedRoleAsync(roleManager, GlobalConstants.UserRoleName);
        }
Beispiel #5
0
        public async Task SeedAsync(CinemaWorldDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.Settings.Any())
            {
                return;
            }

            await dbContext.Settings.AddAsync(new Setting { Name = "Setting1", Value = "value1" });
        }
Beispiel #6
0
        private void InitializeDatabaseAndRepositories()
        {
            this.connection = new SqliteConnection("DataSource=:memory:");
            this.connection.Open();
            var options   = new DbContextOptionsBuilder <CinemaWorldDbContext>().UseSqlite(this.connection);
            var dbContext = new CinemaWorldDbContext(options.Options);

            dbContext.Database.EnsureCreated();

            this.cinemasRepository = new EfDeletableEntityRepository <Cinema>(dbContext);
        }
        private void InitializeDatabaseAndRepositories()
        {
            this.connection = new SqliteConnection("DataSource=:memory:");
            this.connection.Open();
            var options   = new DbContextOptionsBuilder <CinemaWorldDbContext>().UseSqlite(this.connection);
            var dbContext = new CinemaWorldDbContext(options.Options);

            dbContext.Database.EnsureCreated();

            this.userContactsRepository  = new EfRepository <ContactFormEntry>(dbContext);
            this.adminContactsRepository = new EfRepository <AdminContactFromEntry>(dbContext);
        }
        private void InitializeDatabaseAndRepositories()
        {
            this.connection = new SqliteConnection("DataSource=:memory:");
            this.connection.Open();
            var options   = new DbContextOptionsBuilder <CinemaWorldDbContext>().UseSqlite(this.connection);
            var dbContext = new CinemaWorldDbContext(options.Options);

            dbContext.Database.EnsureCreated();

            this.ticketsRepository          = new EfDeletableEntityRepository <Ticket>(dbContext);
            this.seatsRepository            = new EfDeletableEntityRepository <Seat>(dbContext);
            this.movieProjectionsRepository = new EfDeletableEntityRepository <MovieProjection>(dbContext);
            this.hallsRepository            = new EfDeletableEntityRepository <Hall>(dbContext);
            this.cinemasRepository          = new EfDeletableEntityRepository <Cinema>(dbContext);
            this.moviesRepository           = new EfDeletableEntityRepository <Movie>(dbContext);
            this.directorsRepository        = new EfDeletableEntityRepository <Director>(dbContext);
        }
Beispiel #9
0
        public async Task SeedAsync(CinemaWorldDbContext dbContext, IServiceProvider serviceProvider)
        {
            // Custom seed halls with requested amount of seats
            if (!dbContext.Seats.Any())
            {
                return;
            }

            var seats = new List <Seat>();

            for (int row = 1; row <= 10; row++)
            {
                for (int col = 1; col <= 10; col++)
                {
                    int category = this.random.Next((int)SeatCategory.Normal, (int)SeatCategory.Wheelchair + 1);

                    var seat = new Seat
                    {
                        RowNumber = row,
                        Number    = col,
                        HallId    = 7,
                        Category  = (SeatCategory)category,
                    };

                    seats.Add(seat);
                }
            }

            foreach (var seat in seats)
            {
                await dbContext.Seats.AddAsync(new Seat
                {
                    RowNumber   = seat.RowNumber,
                    Number      = seat.Number,
                    IsAvailable = true,
                    HallId      = seat.HallId,
                    Category    = seat.Category,
                });
            }

            await dbContext.SaveChangesAsync();
        }
 public EfRepository(CinemaWorldDbContext context)
 {
     this.Context = context ?? throw new ArgumentNullException(nameof(context));
     this.DbSet   = this.Context.Set <TEntity>();
 }
 public EfDeletableEntityRepository(CinemaWorldDbContext context)
     : base(context)
 {
 }