Beispiel #1
0
        private async Task CreateUsersAsync()
        {
            // local variables
            DateTime createdDate      = new DateTime(2016, 03, 01, 12, 30, 00);
            DateTime lastModifiedDate = DateTime.Now;
            string   adminRole        = "Administrators";
            string   managerRole      = "Manager";
            string   employeeRole     = "Registered";

            //Create Roles (if they doesn't exist yet)
            if (!await _roleManager.RoleExistsAsync(adminRole))
            {
                await _roleManager.CreateAsync(new EmployeeRole()
                {
                    Name = adminRole, CreatedDate = createdDate, UpdatedDate = lastModifiedDate, CreateUserId = 0, UpdateUserId = 0
                });
            }

            if (!await _roleManager.RoleExistsAsync(employeeRole))
            {
                await _roleManager.CreateAsync(new EmployeeRole()
                {
                    Name = employeeRole, CreatedDate = createdDate, UpdatedDate = lastModifiedDate, CreateUserId = 0, UpdateUserId = 0
                });
            }

            if (!await _roleManager.RoleExistsAsync(managerRole))
            {
                await _roleManager.CreateAsync(new EmployeeRole()
                {
                    Name = managerRole, CreatedDate = createdDate, UpdatedDate = lastModifiedDate, CreateUserId = 0, UpdateUserId = 0
                });
            }

            // Create the "Admin" ApplicationUser account (if it doesn't exist already)
            var adminUser = new Employee()
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                CreatedDate  = createdDate,
                UpdatedDate  = lastModifiedDate,
                CreateUserId = 0, // has been generated automatically
                UpdateUserId = 0, // has been generated automatically
            };

            await SaveEmployeeAsync(adminUser, "Pass4admin", adminRole);

#if DEBUG
            var johnDoeUser = new Employee()
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                CreatedDate  = createdDate,
                CreateUserId = 0, // has been generated automatically
                UpdateUserId = 0, // has been generated automatically
            };

            await SaveEmployeeAsync(johnDoeUser, "Pass4john", employeeRole);

            var aliceUser = new Employee()
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                CreatedDate  = createdDate,
                UpdatedDate  = lastModifiedDate,
                CreateUserId = 0, // has been generated automatically
                UpdateUserId = 0, // has been generated automatically
            };

            await SaveEmployeeAsync(aliceUser, "Pass4alice", employeeRole);

            var robertUser = new Employee()
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                CreatedDate  = createdDate,
                UpdatedDate  = lastModifiedDate,
                CreateUserId = 0, // has been generated automatically
                UpdateUserId = 0, // has been generated automatically
            };

            await SaveEmployeeAsync(robertUser, "Pass4robert", managerRole);
#endif
            await _dbContext.SaveChangesAsync();
        }
Beispiel #2
0
 public Task <int> CommitAsync()
 {
     return(_context.SaveChangesAsync());
 }