Esempio n. 1
0
        public async Task SeedAsync(PhotoPavilionDbContext dbContext, IServiceProvider serviceProvider)
        {
            var roleManager = serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >();

            await SeedRoleAsync(roleManager, GlobalConstants.AdministratorRoleName);
            await SeedRoleAsync(roleManager, GlobalConstants.UserRoleName);
        }
Esempio n. 2
0
        public async Task SeedAsync(PhotoPavilionDbContext 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(PhotoPavilionDbContextSeeder));

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

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

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
        private void InitializeDatabaseAndRepositories()
        {
            this.connection = new SqliteConnection("DataSource=:memory:");
            this.connection.Open();
            var options   = new DbContextOptionsBuilder <PhotoPavilionDbContext>().UseSqlite(this.connection);
            var dbContext = new PhotoPavilionDbContext(options.Options);

            dbContext.Database.EnsureCreated();

            this.privaciesRepository = new EfDeletableEntityRepository <Privacy>(dbContext);
        }
Esempio n. 4
0
        private void InitializeDatabaseAndRepositories()
        {
            this.connection = new SqliteConnection("DataSource=:memory:");
            this.connection.Open();
            var options   = new DbContextOptionsBuilder <PhotoPavilionDbContext>().UseSqlite(this.connection);
            var dbContext = new PhotoPavilionDbContext(options.Options);

            dbContext.Database.EnsureCreated();

            this.usersRepository         = new EfDeletableEntityRepository <PhotoPavilionUser>(dbContext);
            this.productsRepository      = new EfDeletableEntityRepository <Product>(dbContext);
            this.brandsRepository        = new EfDeletableEntityRepository <Brand>(dbContext);
            this.categoriesRepository    = new EfDeletableEntityRepository <Category>(dbContext);
            this.shoppingCartsRepository = new EfDeletableEntityRepository <ShoppingCart>(dbContext);
        }
Esempio n. 5
0
 public EfDeletableEntityRepository(PhotoPavilionDbContext context)
     : base(context)
 {
 }
Esempio n. 6
0
 public EfRepository(PhotoPavilionDbContext context)
 {
     this.Context = context ?? throw new ArgumentNullException(nameof(context));
     this.DbSet   = this.Context.Set <TEntity>();
 }