Beispiel #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();
            }
        }
Beispiel #2
0
        public async Task <int> CommitAsync()
        {
            if (_isCommited)
            {
                throw new NotSupportedException("Cannot commit commited UOW");
            }
            if (_isDisposed)
            {
                throw new NotSupportedException("Cannot commit disposed UOW");
            }
            if (_isReadOnly)
            {
                throw new NotSupportedException("Cannot commit readonly UOW");
            }

            var result = await _context.SaveChangesAsync();

            _transaction.Commit();

            _isCommited = true;

            return(result);
        }