コード例 #1
0
 public static void Initialize(IServiceProvider serviceProvider, RCDataContext context)
 {
     try
     {
         if (!context.Users.ToList().Any())
         {
             Task.Run(() => CreateRolesAndUsers(serviceProvider, context)).Wait();
         }
     }
     catch (Exception e)
     {
     }
 }
コード例 #2
0
        public static async Task CreateRolesAndUsers(IServiceProvider serviceProvider, RCDataContext context)
        {
            var roleManager = serviceProvider.GetService <RoleManager <Role> >();
            var userManager = serviceProvider.GetService <UserManager <User> >();

            // In Startup iam creating first Admin Role and creating a default Admin User

            #region Create Roles

            await roleManager.CreateAsync(new Role("Admin"));

            #endregion

            #region Create User
            var user = new User();
            user.UserName  = "******";
            user.Email     = "*****@*****.**";
            user.FirstName = "AdminFirstName";
            user.LastName  = "AdminLastName";
            user.Status    = UserStatus.Active;
            string userPWD = "123@123Aa";

            await userManager.CreateAsync(user, userPWD);

            await context.SaveChangesAsync();

            #endregion
        }