コード例 #1
0
        public bool UpdateRole(ProfileModelDto profile,bool createIfNotExist)
        {
            var role = profile.Role;
            var userName = profile.LoginName;
            try
            {
                if (!String.IsNullOrWhiteSpace(role))
                {
                    if (_roleProvider.RoleExists(role) && !_roleProvider.IsUserInRole(userName, role))
                    {
                        DeleteUserFromRoles(userName);
                        _roleProvider.AddUserToRole(userName, role);
                    }
                    else if (!_roleProvider.RoleExists(role) && createIfNotExist)
                    {
                        _roleProvider.CreateRole(role);
                        DeleteUserFromRoles(userName);
                        _roleProvider.AddUserToRole(userName, role);
                    }

                }
                else
                {
                    DeleteUserFromRoles(userName);
                }
                return true;
            }
            catch (Exception ex)
            {
                Logger.Error("Error : ProfileService.UpdateRole - {0}", ex.Message);
                return false;
            }
        }
コード例 #2
0
 private void CreateTestData()
 {
     _registeredUserId    = _userRegistrationService.Register("UserName", "VeryHardPassword123");
     _registeredAdminId   = _userRegistrationService.Register("AdminName", "VeryHardPassword123");
     _registeredAdminRole = "Admin";
     _registeredUserRole  = "User";
     _roleProvider.CreateRole(_registeredAdminRole, false);
     _roleProvider.CreateRole(_registeredUserRole, false);
     _roleProvider.AddUserToRole(_registeredAdminId, _registeredAdminRole);
 }
コード例 #3
0
        private void SetDefaultUsersAndRoles()
        {
            Guid userId = _userRegistrationService.Register(DefaultAdminName, DefaultAdminPassword, false);

            _roleProvider.CreateRole(AdministratorRoleName, false);
            _roleProvider.AddUserToRole(userId, AdministratorRoleName);
        }
コード例 #4
0
        private static void SetDefaultUsersAndRoles()
        {
            IUserRegistrationService registrationService = bootstrapper.Kernel.Get <IUserRegistrationService>();
            IRoleProvider            roleProvider        = bootstrapper.Kernel.Get <IRoleProvider>();
            Guid userId = registrationService.Register("Timur", "Admin", false);

            roleProvider.CreateRole("Administrator", false);
            roleProvider.AddUserToRole(userId, "Administrator");
        }