public async Task <DResult <int> > AddPrivilegeForRole([FromBody] RelationRolePrivilegeAddDto relationRolePrivileges) { try { return(DResult.Succ(businessPrivilege.AddPrivilegeForRole(relationRolePrivileges))); } catch (Exception ex) { Logger.Error(ex.ToString()); return(DResult.Error <int>(ExceptionParse.ParseString(ex.Message), 500)); } }
/// <summary> /// 为角色关联权限 /// </summary> /// <param name="vRelationRolePrivilegeAdds"></param> /// <returns></returns> public int AddPrivilegeForRole(RelationRolePrivilegeAddDto vRelationRolePrivilegeAdds) { IList <TRelationRolePrivilege> relationRolePrivileges = new List <TRelationRolePrivilege>(); foreach (string privilege in vRelationRolePrivilegeAdds.PrivilegeIds) { TRelationRolePrivilege relationRolePrivilege = new TRelationRolePrivilege { Id = IdentityHelper.NewSequentialGuid().ToString("N"), RoleId = vRelationRolePrivilegeAdds.RoleId, PrivilegeId = privilege, PrivilegeCode = IocUnity.Get <RepositoryPrivilege>().GetPrivilegeCode(privilege) }; relationRolePrivileges.Add(relationRolePrivilege); } int count = 0; IocUnity.Get <RepositoryRelationRolePrivilege>().DapperRepository.ExcuteTransaction(tranc => { IocUnity.Get <RepositoryRelationRolePrivilege>().Delete(vRelationRolePrivilegeAdds.RoleId); count = IocUnity.Get <RepositoryRelationRolePrivilege>().Insert(relationRolePrivileges); }); return(count); }