/// <summary> /// 保存权限 /// </summary> /// <param name="authority">权限对象</param> /// <returns>执行结果</returns> public static Result <Authority> SaveAuthority(Authority authority) { if (authority == null) { return(Result <Authority> .FailedResult("权限信息为空")); } //权限分组 if (authority.AuthGroup == null || authority.AuthGroup.SysNo <= 0) { return(Result <Authority> .FailedResult("请设置正确的权限组")); } if (!AuthorityGroupService.ExistAuthorityGroup(authority.AuthGroup.SysNo)) { return(Result <Authority> .FailedResult("请设置正确的权限组")); } Authority nowAuthority = GetAuthority(authority.Code); if (nowAuthority == null) { nowAuthority = authority; nowAuthority.AuthType = AuthorityType.管理; nowAuthority.CreateDate = DateTime.Now; nowAuthority.Sort = 0; } else { //nowAuthority.Code = authority.Code; nowAuthority.Name = authority.Name; nowAuthority.Status = authority.Status; nowAuthority.Remark = authority.Remark; } nowAuthority.Save(); var result = Result <Authority> .SuccessResult("保存成功"); result.Data = nowAuthority; return(result); }
/// <summary> /// 加载其它数据 /// </summary> /// <param name="authoritys">权限数据</param> /// <param name="query">筛选条件</param> /// <returns></returns> static List <Authority> LoadOtherObjectData(IEnumerable <Authority> authoritys, IQuery query) { if (authoritys.IsNullOrEmpty()) { return(new List <Authority>(0)); } if (query == null) { return(authoritys.ToList()); } #region 权限分组 List <AuthorityGroup> groupList = null; if (query.AllowLoad <Authority>(c => c.AuthGroup)) { var groupIds = authoritys.Select(c => c.AuthGroup?.SysNo ?? 0).Distinct().ToList(); groupList = AuthorityGroupService.GetAuthorityGroupList(groupIds); } #endregion foreach (var auth in authoritys) { if (auth == null) { continue; } if (!groupList.IsNullOrEmpty()) { auth.SetGroup(groupList.FirstOrDefault(c => c.SysNo == auth.AuthGroup?.SysNo)); } } return(authoritys.ToList()); }