public async Task <bool> Handle(SavePermissionCommand request, CancellationToken cancellationToken) { var oldPermissions = await _permissionRepository.GetWhereAsync(x => x.AppliedObjectType == request.AppliedObjectType && request.ValidateObjectType == x.ValidateObjectType && request.AppliedID == x.AppliedID); await _permissionRepository.DeleteRangeAsync(oldPermissions); var newPermissions = request.ObjectPermissions.Select(x => { var bp = new BasalPermission() { AppliedID = request.AppliedID, AppliedObjectID = x.AppliedObjectID, AppliedObjectType = request.AppliedObjectType, ValidateObjectType = request.ValidateObjectType }; foreach (var permission in x.PermissionOpeation) { bp.SetBit(permission, AccessControlEntry.Allow); } return(bp); } ).ToList(); await _permissionRepository.AddRangeAsync(newPermissions); if (await Commit()) { await _bus.RaiseEvent(new RemoveServiceCacheEvent(), cancellationToken); } return(true); }
public async Task <bool> Handle(ModifyPermissionCommand request, CancellationToken cancellationToken) { //首先将对应的permission都删除 await _permissionRepository.RemoveRangeByRoleId(request.RoleId); List <Permission> permissions = new List <Permission>(); foreach (var item in request.Permissions) { permissions.Add(new Permission() { ActionName = item.Action, ControllerName = item.Controller, RoleId = request.RoleId }); } await _permissionRepository.AddRangeAsync(permissions); if (await CommitAsync()) { return(true); } return(false); }