public void EnsureGroupsInstalled() { var groups = _groupProvider.GetAll(); foreach (var group in groups) { _groupService.Save(group, false); var defaultGroups = _groupProvider.GetDefaults(); foreach (var defaultGroup in defaultGroups) { var role = _roleService.Get(defaultGroup.Role, true, false); if (role == null) { role = _roleService.Save(defaultGroup.Role, defaultGroup.Role).Value; } var defaultMappingProvided = defaultGroup.Groups.Any(pg => pg.InternalKey == group.InternalKey); var mappingExists = role.Groups.Any(pg => pg.InternalKey == group.InternalKey); if (defaultMappingProvided && !mappingExists) { group.Roles.Add(role); } } _groupService.Save(group, false); } }
/// <summary> /// 保存权限分组 /// </summary> /// <param name="savePermissionGroupDto">权限分组保存信息</param> /// <returns>返回执行结果</returns> public Result <PermissionGroupDto> SavePermissionGroup(SavePermissionGroupDto savePermissionGroupDto) { if (savePermissionGroupDto?.PermissionGroup == null) { return(Result <PermissionGroupDto> .FailedResult("分组信息不完整")); } using (var businessWork = WorkManager.Create()) { var saveResult = permissionGroupService.Save(savePermissionGroupDto.PermissionGroup.MapTo <PermissionGroup>()); if (!saveResult.Success) { return(Result <PermissionGroupDto> .FailedResult(saveResult.Message)); } var commitResult = businessWork.Commit(); Result <PermissionGroupDto> result = null; if (commitResult.EmptyResultOrSuccess) { result = Result <PermissionGroupDto> .SuccessResult("保存成功"); result.Data = saveResult.Data.MapTo <PermissionGroupDto>(); } else { result = Result <PermissionGroupDto> .FailedResult("保存失败"); } return(result); } }
public OperationResult AddRoleToGroup(PermissionGroupEntity group, RoleEntity role) { var result = EngineContext.Current.Resolve <OperationResult>(); if (group == null) { return(result.AddError(Messages.Authorization_InvalidGroup)); } if (role == null) { return(result.AddError(Messages.Authorization_InvalidRole)); } if (@group.Roles.All(r => r != role)) { group.Roles.Add(role); result += _groupService.Save(group, false); } return(result); }