Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/17 17:51:28 (7 years ago)
Author:
jzenisek
Message:

#2839

  • worked on Job operations add&update
  • worked on ProjectPermission handling
  • worked on Project-Resource assignment
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs

    r15411 r15530  
    4545    }
    4646
     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
    4764    #region Compiled queries
    4865    private static readonly Func<DataContext, Guid, IEnumerable<AssignedProjectResource>> GetByProjectIdGetByIdQuery =
     
    5875         WHERE ProjectId = '{0}'
    5976           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    ";
    60142    #endregion
    61143  }
Note: See TracChangeset for help on using the changeset viewer.