/// <summary> /// 添加权限分组 /// </summary> /// <param name="permissionGroup">权限信息</param> /// <returns>执行结果</returns> Result <PermissionGroup> AddPermissionGroup(PermissionGroup permissionGroup) { #region 级 long parentGroupId = permissionGroup.Parent == null ? 0 : permissionGroup.Parent.Id; PermissionGroup parentGroup = null; if (parentGroupId > 0) { IQuery parentQuery = QueryManager.Create <PermissionGroupEntity>(c => c.Id == parentGroupId); parentGroup = permissionGroupRepository.Get(parentQuery); if (parentGroup == null) { return(Result <PermissionGroup> .FailedResult("请选择正确的上级分组")); } } permissionGroup.SetParent(parentGroup); #endregion permissionGroup.Save();//保存 var result = Result <PermissionGroup> .SuccessResult("添加成功"); result.Data = permissionGroup; return(result); }
/// <summary> /// 更新权限分组 /// </summary> /// <param name="newPermissionGroup">权限信息</param> /// <returns>执行结果</returns> Result <PermissionGroup> UpdatePermissionGroup(PermissionGroup newPermissionGroup) { PermissionGroup currentPermissionGroup = permissionGroupRepository.Get(QueryManager.Create <PermissionGroupEntity>(r => r.Id == newPermissionGroup.Id)); if (currentPermissionGroup == null) { return(Result <PermissionGroup> .FailedResult("没有指定要操作的分组信息")); } //上级 long newParentGroupId = newPermissionGroup.Parent == null ? 0 : newPermissionGroup.Parent.Id; long oldParentGroupId = currentPermissionGroup.Parent == null ? 0 : currentPermissionGroup.Parent.Id; //上级改变后 if (newParentGroupId != oldParentGroupId) { PermissionGroup parentGroup = null; if (newParentGroupId > 0) { IQuery parentQuery = QueryManager.Create <PermissionGroupEntity>(c => c.Id == newParentGroupId); parentGroup = permissionGroupRepository.Get(parentQuery); if (parentGroup == null) { return(Result <PermissionGroup> .FailedResult("请选择正确的上级分组")); } } currentPermissionGroup.SetParent(parentGroup); } //修改信息 currentPermissionGroup.Name = newPermissionGroup.Name; currentPermissionGroup.Remark = newPermissionGroup.Remark; currentPermissionGroup.Save();//保存 var result = Result <PermissionGroup> .SuccessResult("更新成功"); result.Data = currentPermissionGroup; return(result); }