예제 #1
0
        public async Task Seed(AuroraContext context, UserManager <UserEntity> userManager, RoleManager <IdentityRole> roleManager)
        {
            var wasDatabseCreationEnsured = await context.Database.EnsureCreatedAsync();

            //*************SEED***************//

            if (wasDatabseCreationEnsured)
            {
                await roleManager.CreateAsync(new IdentityRole { Name = RoleNames.Admin });

                var adminUser = await CreateUser(new UserEntity { UserName = "******", Email = "*****@*****.**" }, userManager);

                var adminRole = await roleManager.FindByNameAsync(RoleNames.Admin);

                context.UserRoles.Add(new IdentityUserRole <string> {
                    UserId = adminUser.Id, RoleId = adminRole.Id
                });

                for (var i = 0; i < 100; ++i)
                {
                    await CreateUser(new UserEntity { UserName = $"user{i}", Email = $"user{i}@aurora.com" }, userManager);
                }

                await context.SaveChangesAsync();
            }
        }
예제 #2
0
        public UnitOfWork(AuroraContext context, bool isReadOnly)
        {
            _context    = context;
            _isReadOnly = isReadOnly;

            if (!isReadOnly)
            {
                _transaction = context.Database.BeginTransaction();
            }
        }