Changeset 15577 for branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs
- Timestamp:
- 01/05/18 15:13:25 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs
r15552 r15577 33 33 } 34 34 35 public IEnumerable<Project> GetGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) { 36 return GetGrantedProjectsForUserQuery(DataContext, userAndGroupIds); 35 public IEnumerable<Project> GetUsageGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) { 36 string paramUserAndGroupIds = string.Join(",", userAndGroupIds.ToList().Select(x => string.Format("'{0}'", x))); 37 if (!string.IsNullOrWhiteSpace(paramUserAndGroupIds)) { 38 string queryString = string.Format(GetUsageGrantedProjectsForUserQueryString, paramUserAndGroupIds); 39 return DataContext.ExecuteQuery<Project>(queryString); 40 } 41 return Enumerable.Empty<Project>(); 42 } 43 44 public IEnumerable<Project> GetAdministrationGrantedProjectsForUser(Guid userId) { 45 return DataContext.ExecuteQuery<Project>(GetAdministrationGrantedProjectsForUserQueryString, userId); 37 46 } 38 47 … … 67 76 where project.ProjectId == projectId 68 77 select project).SingleOrDefault()); 69 private static readonly Func<DataContext, IEnumerable<Guid>, IEnumerable<Project>> GetGrantedProjectsForUserQuery =70 CompiledQuery.Compile((DataContext db, IEnumerable<Guid> userAndGroupIds) =>71 (from project in db.GetTable<Project>()72 join projectPermission in db.GetTable<ProjectPermission>()73 on project.ProjectId equals projectPermission.ProjectId74 where userAndGroupIds.Contains(projectPermission.GrantedUserId)75 select project).Distinct());76 78 #endregion 77 79 78 #region String queries 80 #region String queries 81 private const string GetUsageGrantedProjectsForUserQueryString = @" 82 SELECT DISTINCT p.* 83 FROM [Project] p, [ProjectPermission] pp 84 WHERE p.ProjectId = pp.ProjectId 85 AND pp.GrantedUserId IN ({0}) 86 "; 87 88 private const string GetAdministrationGrantedProjectsForUserQueryString = @" 89 WITH ptree AS 90 ( 91 SELECT ProjectId, ParentProjectId 92 FROM [Project] 93 UNION ALL 94 SELECT pt.ProjectId, p.ParentProjectId 95 FROM [Project] p 96 JOIN ptree pt ON pt.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pt.ParentProjectId <> pt.ProjectId 97 ) 98 SELECT DISTINCT parent.* 99 FROM [Project] parent 100 WHERE parent.OwnerUserId = {0} 101 UNION 102 SELECT DISTINCT child.* 103 FROM ptree, [Project] parent, [Project] child 104 WHERE ptree.ParentProjectId = parent.ProjectId 105 AND ptree.ProjectId = child.ProjectId 106 AND parent.OwnerUserId = {0} 107 "; 108 79 109 private const string GetChildProjectsByIdQuery = @" 80 110 WITH ptree AS
Note: See TracChangeset
for help on using the changeset viewer.