public void CreateRole(string roleName) {
            if (GetRoleByName(roleName) != null)
                return;

            var roleRecord = new RoleRecord {Name = roleName};
            _roleRepository.Create(roleRecord);
            _roleEventHandlers.Created(new RoleCreatedContext { Role = roleRecord });
            TriggerSignal();
        }
Beispiel #2
0
        private void PrintRoleRecord(RoleRecord roleRecord, int initialIndent = 0) {
            var secondIndent = initialIndent + 2;

            Context.Output.Write(new string(' ', initialIndent));
            Context.Output.WriteLine(T("{0}", roleRecord.Name));

            if (IncludePermissions) {
                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("List of Permissions"));

                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("--------------------------"));

                var permissionsEnumerable =
                    roleRecord.RolesPermissions
                        .Where(record => WithFeature == null || record.Permission.FeatureName == WithFeature)
                        .Where(record => WithPermission == null || record.Permission.Name == WithPermission);

                var orderedPermissionsEnumerable =
                    permissionsEnumerable
                        .OrderBy(record => record.Permission.FeatureName)
                        .ThenBy(record => record.Permission.Name);

                foreach (var rolesPermissionsRecord in orderedPermissionsEnumerable) {
                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("Feature Name:".PadRight(15));
                    Context.Output.WriteLine(rolesPermissionsRecord.Permission.FeatureName);

                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("Permission:".PadRight(15));
                    Context.Output.WriteLine(rolesPermissionsRecord.Permission.Name);

                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("Description:".PadRight(15));
                    Context.Output.WriteLine(rolesPermissionsRecord.Permission.Description);
                    Context.Output.WriteLine();
                }
            }

            if (IncludeUsers) {
                var userRolesPartRecords = _userRolesRepository.Fetch(record => record.Role.Name == roleRecord.Name);

                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("List of Users"));

                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("--------------------------"));

                foreach (var userRolesPartRecord in userRolesPartRecords) {
                    var userRolesPart = _contentManager.Get<UserRolesPart>(userRolesPartRecord.UserId);
                    var user = userRolesPart.As<IUser>();
                    
                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("UserName:"******"Email:".PadRight(15));
                    Context.Output.WriteLine(user.Email);
                    Context.Output.WriteLine();
                }
            }
        }