コード例 #1
0
        private void AddFirstAdminAndRoles()
        {
            UserAppService userAppService = new UserAppService();
            RoleAppService roleAppService = new RoleAppService();

            roleAppService.AddOrUpdate("admin");
            roleAppService.AddOrUpdate("client");
            RegisterViewModel user = new RegisterViewModel()
            {
                FirstName    = "first",
                LastName     = "user",
                UserName     = "******",
                PasswordHash = "admin12345"
            };

            if (!userAppService.CheckExist("admin"))
            {
                userAppService.Register(user);
                ApplicationUserIdentity registeredUser = userAppService.FindByUserName(user.UserName);
                userAppService.AssignToRole(registeredUser.Id, "admin");
            }
        }