- Timestamp:
- 12/20/17 11:27:33 (7 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
r15530 r15552 18 18 } 19 19 20 public void DeleteByProjectId(Guid projectId) { 21 DataContext.ExecuteCommand(DeleteByProjectIdQueryString, projectId); 22 } 23 24 public void DeleteByProjectIdAndUserIds(Guid projectId, IEnumerable<Guid> userIds) { 25 string paramUserIds = string.Join(",", userIds.Select(x => string.Format("'{0}'", x))); 26 if (!string.IsNullOrWhiteSpace(paramUserIds)) { 27 string queryString = string.Format(DeleteByProjectIdAndUserIdsQueryString, projectId, paramUserIds); 28 DataContext.ExecuteCommand(queryString); 29 } 30 } 31 32 public void DeleteByProjectIdsAndUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> userIds) { 33 string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x))); 34 string paramUserIds = string.Join(",", userIds.Select(x => string.Format("'{0}'", x))); 35 if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) { 36 string queryString = string.Format(DeleteByProjectIdsAndUserIdsQueryString, paramProjectIds, paramUserIds); 37 DataContext.ExecuteCommand(queryString); 38 } 39 } 40 41 public void DeleteByProjectIdAndResourceIds(Guid projectId, IEnumerable<Guid> resourceIds) { 42 string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x))); 43 if (!string.IsNullOrWhiteSpace(paramResourceIds)) { 44 string queryString = string.Format(DeleteByProjectIdAndResourceIdsQueryString, projectId, paramResourceIds); 45 DataContext.ExecuteCommand(queryString); 46 } 47 } 48 49 public void DeleteByProjectIdsAndResourceIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> resourceIds) { 50 string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x))); 51 string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x))); 52 if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramResourceIds)) { 53 string queryString = string.Format(DeleteByProjectIdsAndResourceIdsQueryString, paramProjectIds, paramResourceIds); 54 DataContext.ExecuteCommand(queryString); 55 } 56 } 57 20 58 public bool CheckJobGrantedForResource(Guid jobId, Guid resourceId) { 21 59 return DataContext.ExecuteQuery<int>(CheckJobGrantedForResourceQueryString, jobId, resourceId).First() > 0; … … 44 82 45 83 #region String queries 84 private const string DeleteByProjectIdQueryString = @" 85 DELETE FROM [AssignedJobResource] ajr 86 WHERE ajr.JobId IN 87 ( 88 SELECT j.JobId 89 FROM [Job] j 90 WHERE j.ProjectId = {0} 91 ) 92 "; 93 private const string DeleteByProjectIdAndUserIdsQueryString = @" 94 DELETE FROM [AssignedJobResource] ajr 95 WHERE ajr.JobId IN 96 ( 97 SELECT j.JobId 98 FROM [Job] j 99 WHERE j.ProjectId = {0} 100 AND j.OwnerUserId IN ({1}) 101 ) 102 "; 103 private const string DeleteByProjectIdsAndUserIdsQueryString = @" 104 DELETE FROM [AssignedJobResource] ajr 105 WHERE ajr.JobId IN 106 ( 107 SELECT j.JobId 108 FROM [Job] j 109 WHERE j.ProjectId IN ({0}) 110 AND j.OwnerUserId IN ({1}) 111 ) 112 "; 113 private const string DeleteByProjectIdAndResourceIdsQueryString = @" 114 DELETE FROM [AssignedJobResource] ajr 115 WHERE ajr.JobId IN 116 ( 117 SELECT j.JobId 118 FROM [Job] j 119 WHERE j.ProjectId = {0} 120 ) 121 AND ajr.ResourceId IN ({1}) 122 "; 123 private const string DeleteByProjectIdsAndResourceIdsQueryString = @" 124 DELETE FROM [AssignedJobResource] ajr 125 WHERE ajr.JobId IN 126 ( 127 SELECT j.JobId 128 FROM [Job] j 129 WHERE j.ProjectId IN ({0}) 130 ) 131 AND ajr.ResourceId IN ({1}) 132 "; 46 133 private const string CheckJobGrantedForResourceQueryString = @" 47 134 WITH rbranch AS ( -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs
r15540 r15552 31 31 public override Project GetById(Guid id) { 32 32 return GetByIdQuery(DataContext, id); 33 } 34 35 public IEnumerable<Project> GetGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) { 36 return GetGrantedProjectsForUserQuery(DataContext, userAndGroupIds); 33 37 } 34 38 … … 63 67 where project.ProjectId == projectId 64 68 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.ProjectId 74 where userAndGroupIds.Contains(projectPermission.GrantedUserId) 75 select project).Distinct()); 65 76 #endregion 66 77 67 #region String queries78 #region String queries 68 79 private const string GetChildProjectsByIdQuery = @" 69 80 WITH ptree AS -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs
r15530 r15552 88 88 AND pp.GrantedUserId IN ({1}) 89 89 "; 90 private const string GetGrantedProjectsForUserQueryString = @" 91 SELECT DISTINCT p.* 92 FROM [ProjectPermission] pp, [Project] p 93 WHERE pp.GrantedUserId IN ({0}) 94 AND pp.ProjectId = p.ProjectId 95 "; 90 96 #endregion 91 97 }
Note: See TracChangeset
for help on using the changeset viewer.