From f6cf9e5ee0eaa80a676404c1b89240b13830726d Mon Sep 17 00:00:00 2001 From: yubaolee Date: Sat, 15 Apr 2017 22:43:21 +0800 Subject: [PATCH] check issue #37 --- .../OpenAuth.Repository.csproj | 2 +- OpenAuth.Repository/ResourceRepository.cs | 97 ++++++++----------- OpenAuth.Repository/RoleRepository.cs | 49 +++++++--- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/OpenAuth.Repository/OpenAuth.Repository.csproj b/OpenAuth.Repository/OpenAuth.Repository.csproj index 168e3ca6..c4806c59 100644 --- a/OpenAuth.Repository/OpenAuth.Repository.csproj +++ b/OpenAuth.Repository/OpenAuth.Repository.csproj @@ -79,8 +79,8 @@ - + diff --git a/OpenAuth.Repository/ResourceRepository.cs b/OpenAuth.Repository/ResourceRepository.cs index cda11ca2..139af2e6 100644 --- a/OpenAuth.Repository/ResourceRepository.cs +++ b/OpenAuth.Repository/ResourceRepository.cs @@ -1,57 +1,40 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using OpenAuth.Domain; -using OpenAuth.Domain.Interface; - -namespace OpenAuth.Repository -{ - public class RoleRepository :BaseRepository, IRoleRepository - { - public IEnumerable LoadRoles(int pageindex, int pagesize) - { - return Context.Roles.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); - } - - public int GetRoleCntInOrgs(params Guid[] orgIds) - { - return LoadInOrgs(orgIds).Count(); - } - - public IEnumerable LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds) - { - return LoadInOrgs(orgIds).OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); - } - - public void Delete(Guid id) - { - Delete(u =>u.Id == id); - } - - public IEnumerable LoadInOrgs(params Guid[] orgId) - { - var roles = Context.Relevances.Where(u => u.Key == "RoleOrg" - && orgId.Contains(u.SecondId)).Select(u => u.FirstId); //机构关联的角色 - - var result = from role in Context.Roles.Where(u =>roles.Contains(u.Id)) select role; - - return result; - - } - - public IEnumerable LoadForUser(Guid userId) - { - - if (userId == Guid.Empty) - return Find(null); - - var userRoleIds = - Context.Relevances.Where(u => u.FirstId == userId && u.Key == "UserRole") - .Select(u => u.SecondId).ToList(); - - return Find(u => userRoleIds.Contains(u.Id)); - } - } -} +using System; +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Repository +{ + public class ResourceRepository : BaseRepository, IResourceRepository + { + public IEnumerable LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds) + { + return LoadInOrgs(orgIds).OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); + } + + public void Delete(Guid id) + { + Delete(u => u.Id == id); + } + + public IEnumerable LoadInOrgs(params Guid[] orgId) + { + bool isZero = orgId.Length == 1 && orgId[0] == Guid.Empty; //判断传进来的是否为0 + var result = from resource in Context.Resources.Where(u =>isZero + || u.CascadeId != null &&orgId.Contains(u.CategoryId.Value)) select resource; + + return result; + } + + public IEnumerable LoadResources(int pageindex, int pagesize) + { + return Context.Resources.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); + } + + public int GetResourceCntInOrgs(params Guid[] orgIds) + { + return LoadInOrgs(orgIds).Count(); + } + } +} \ No newline at end of file diff --git a/OpenAuth.Repository/RoleRepository.cs b/OpenAuth.Repository/RoleRepository.cs index 139af2e6..309f4b23 100644 --- a/OpenAuth.Repository/RoleRepository.cs +++ b/OpenAuth.Repository/RoleRepository.cs @@ -1,40 +1,57 @@ using System; -using OpenAuth.Domain; -using OpenAuth.Domain.Interface; using System.Collections.Generic; using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; namespace OpenAuth.Repository { - public class ResourceRepository : BaseRepository, IResourceRepository + public class RoleRepository :BaseRepository, IRoleRepository { - public IEnumerable LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds) + public IEnumerable LoadRoles(int pageindex, int pagesize) + { + return Context.Roles.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); + } + + public int GetRoleCntInOrgs(params Guid[] orgIds) + { + return LoadInOrgs(orgIds).Count(); + } + + public IEnumerable LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds) { return LoadInOrgs(orgIds).OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); } public void Delete(Guid id) { - Delete(u => u.Id == id); + Delete(u =>u.Id == id); } - public IEnumerable LoadInOrgs(params Guid[] orgId) + public IEnumerable LoadInOrgs(params Guid[] orgId) { - bool isZero = orgId.Length == 1 && orgId[0] == Guid.Empty; //判断传进来的是否为0 - var result = from resource in Context.Resources.Where(u =>isZero - || u.CascadeId != null &&orgId.Contains(u.CategoryId.Value)) select resource; + var roles = Context.Relevances.Where(u => u.Key == "RoleOrg" + && orgId.Contains(u.SecondId)).Select(u => u.FirstId); //机构关联的角色 + var result = from role in Context.Roles.Where(u =>roles.Contains(u.Id)) select role; + return result; + } - public IEnumerable LoadResources(int pageindex, int pagesize) + public IEnumerable LoadForUser(Guid userId) { - return Context.Resources.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); - } - public int GetResourceCntInOrgs(params Guid[] orgIds) - { - return LoadInOrgs(orgIds).Count(); + if (userId == Guid.Empty) + return Find(null); + + var userRoleIds = + Context.Relevances.Where(u => u.FirstId == userId && u.Key == "UserRole") + .Select(u => u.SecondId).ToList(); + + return Find(u => userRoleIds.Contains(u.Id)); } } -} \ No newline at end of file +}