- Timestamp:
- 12/15/17 17:51:28 (6 years ago)
- Location:
- branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedJobResourceDao.cs
r15528 r15530 22 22 } 23 23 24 public bool CheckJobGrantedForResources(Guid jobId, Guid[] resourceIds) { 25 return DataContext.ExecuteQuery<int>(CheckJobGrantedForResourcesQueryString).Count() > 0; 24 public bool CheckJobGrantedForResources(Guid jobId, IEnumerable<Guid> resourceIds) { 25 string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x))); 26 if (!string.IsNullOrWhiteSpace(paramResourceIds)) { 27 string queryString = string.Format(CheckJobGrantedForResourcesQueryString, jobId, paramResourceIds); 28 return DataContext.ExecuteQuery<int>(queryString).Count() == 0; 29 } 30 return false; 26 31 } 27 32 … … 43 48 SELECT ResourceId, ParentResourceId 44 49 FROM [Resource] 45 WHERE ResourceId = { 0}50 WHERE ResourceId = {1} 46 51 UNION ALL 47 52 SELECT r.ResourceId, r.ParentResourceId … … 52 57 FROM rbranch, AssignedJobResource ajr 53 58 WHERE rbranch.ResourceId = ajr.ResourceId 54 AND ajr.JobId = { 1}59 AND ajr.JobId = {0} 55 60 "; 56 61 private const string CheckTaskGrantedForResourceQueryString = @" … … 58 63 SELECT ResourceId, ParentResourceId 59 64 FROM [Resource] 60 WHERE ResourceId = { 0}65 WHERE ResourceId = {1} 61 66 UNION ALL 62 67 SELECT r.ResourceId, r.ParentResourceId … … 68 73 WHERE rbranch.ResourceId = ajr.ResourceId 69 74 AND ajr.JobId = t.JobId 70 AND t.JobId = { 1}75 AND t.JobId = {0} 71 76 "; 72 77 private const string CheckJobGrantedForResourcesQueryString = @" -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs
r15411 r15530 45 45 } 46 46 47 public bool CheckProjectGrantedForResources(Guid projectId, IEnumerable<Guid> resourceIds) { 48 string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x))); 49 if (!string.IsNullOrWhiteSpace(paramResourceIds)) { 50 string queryString = string.Format(CheckProjectGrantedForResourcesQueryString, projectId, paramResourceIds); 51 return DataContext.ExecuteQuery<int>(queryString).Count() == 0; 52 } 53 return false; 54 } 55 56 public IEnumerable<Resource> GetAllGrantedResourcesByProjectId(Guid projectId) { 57 return DataContext.ExecuteQuery<Resource>(GetAllGrantedResourcesByProjectIdQueryString, projectId); 58 } 59 60 public IEnumerable<Guid> GetAllGrantedResourceIdsByProjectId(Guid projectId) { 61 return DataContext.ExecuteQuery<Guid>(GetAllGrantedResourceIdsByProjectIdQueryString, projectId); 62 } 63 47 64 #region Compiled queries 48 65 private static readonly Func<DataContext, Guid, IEnumerable<AssignedProjectResource>> GetByProjectIdGetByIdQuery = … … 58 75 WHERE ProjectId = '{0}' 59 76 AND ResourceId IN ({1});"; 77 private const string CheckProjectGrantedForResourcesQueryString = @" 78 WITH rtree AS 79 ( 80 SELECT ResourceId, ParentResourceId 81 FROM [Resource] 82 UNION ALL 83 SELECT rt.ResourceId, r.ParentResourceId 84 FROM [Resource] r 85 JOIN rtree rt ON rt.ParentResourceId = r.ResourceId 86 ) 87 SELECT r.ResourceId 88 FROM [Resource] r 89 WHERE r.ResourceId IN ({1}) 90 EXCEPT 91 ( 92 SELECT rtree.ResourceId 93 FROM rtree, [AssignedProjectResource] apr 94 WHERE rtree.ParentResourceId = apr.ResourceId 95 AND apr.ProjectId = {0} 96 UNION 97 SELECT apr.ResourceId 98 FROM [AssignedProjectResource] apr 99 WHERE apr.ProjectId = {0} 100 ) 101 "; 102 private const string GetAllGrantedResourcesByProjectIdQueryString = @" 103 WITH rtree AS 104 ( 105 SELECT ResourceId, ParentResourceId 106 FROM [Resource] 107 UNION ALL 108 SELECT rt.ResourceId, r.ParentResourceId 109 FROM [Resource] r 110 JOIN rtree rt ON rt.ParentResourceId = r.ResourceId 111 ) 112 SELECT res.* 113 FROM rtree, [AssignedProjectResource] apr, [Resource] res 114 WHERE rtree.ParentResourceId = apr.ResourceId 115 AND rtree.ResourceId = res.ResourceId 116 AND apr.ProjectId = {0} 117 UNION 118 SELECT res.* 119 FROM [AssignedProjectResource] apr, [Resource] res 120 WHERE apr.ResourceId = res.ResourceId 121 AND apr.ProjectId = {0} 122 "; 123 private const string GetAllGrantedResourceIdsByProjectIdQueryString = @" 124 WITH rtree AS 125 ( 126 SELECT ResourceId, ParentResourceId 127 FROM [Resource] 128 UNION ALL 129 SELECT rt.ResourceId, r.ParentResourceId 130 FROM [Resource] r 131 JOIN rtree rt ON rt.ParentResourceId = r.ResourceId 132 ) 133 SELECT rtree.ResourceId 134 FROM rtree, [AssignedProjectResource] apr 135 WHERE rtree.ParentResourceId = apr.ResourceId 136 AND apr.ProjectId = {0} 137 UNION 138 SELECT apr.ResourceId 139 FROM [AssignedProjectResource] apr 140 WHERE apr.ProjectId = {0} 141 "; 60 142 #endregion 61 143 } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs
r15379 r15530 37 37 } 38 38 39 public void DeleteByProjectAndGrantedUserId(Guid projectId, IEnumerable<Guid> grantedUserId) { 40 string paramIds = string.Join(",", grantedUserId.Select(x => string.Format("'{0}'", x))); 39 public bool CheckUserGrantedForProject(Guid projectId, IEnumerable<Guid> userAndGroupIds) { 40 string paramUserAndGroupIds = string.Join(",", userAndGroupIds.Select(x => string.Format("'{0}'", x))); 41 if(!string.IsNullOrWhiteSpace(paramUserAndGroupIds)) { 42 string queryString = string.Format(CheckUserGrantedForProjectQueryString, projectId, paramUserAndGroupIds); 43 return DataContext.ExecuteQuery<int>(queryString).First() > 0; 44 } 45 return false; 46 } 47 48 public void DeleteByProjectIdAndGrantedUserIds(Guid projectId, IEnumerable<Guid> grantedUserIds) { 49 string paramIds = string.Join(",", grantedUserIds.Select(x => string.Format("'{0}'", x))); 41 50 if (!string.IsNullOrWhiteSpace(paramIds)) { 42 string query = string.Format(DeleteByGrantedUserQuery, projectId, paramIds); 51 string query = string.Format(DeleteByProjectIdAndGrantedUserIdsQueryString, projectId, paramIds); 52 DataContext.ExecuteCommand(query); 53 } 54 } 55 56 public void DeleteByProjectIdsAndGrantedUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> grantedUserIds) { 57 string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x))); 58 string paramUserIds = string.Join(",", grantedUserIds.Select(x => string.Format("'{0}'", x))); 59 if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) { 60 string query = string.Format(DeleteByProjectIdsAndGrantedUserIdsQueryString, paramProjectIds, paramUserIds); 43 61 DataContext.ExecuteCommand(query); 44 62 } … … 54 72 55 73 #region String queries 56 private const string DeleteByGrantedUserQuery = 57 @"DELETE FROM [ProjectPermission] 58 WHERE ProjectId = '{0}' 59 AND GrantedUserId IN ({1});"; 74 private const string DeleteByProjectIdAndGrantedUserIdsQueryString = @" 75 DELETE FROM [ProjectPermission] 76 WHERE ProjectId = '{0}' 77 AND GrantedUserId IN ({1}); 78 "; 79 private const string DeleteByProjectIdsAndGrantedUserIdsQueryString = @" 80 DELETE FROM [ProjectPermission] 81 WHERE ProjectId IN '({0})' 82 AND GrantedUserId IN ({1}); 83 "; 84 private const string CheckUserGrantedForProjectQueryString = @" 85 SELECT COUNT(pp.ProjectId) 86 FROM [ProjectPermission] pp 87 WHERE pp.ProjectId = {0} 88 AND pp.GrantedUserId IN ({1}) 89 "; 60 90 #endregion 61 91 }
Note: See TracChangeset
for help on using the changeset viewer.