Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs @ 15632

Last change on this file since 15632 was 15628, checked in by jzenisek, 7 years ago

#2839

  • updated TaskDao towards independency of the formerly used Task-Resource assignment entity
  • updated several permission/assignment handling service methods for client
  • added AssignedJobResource DTO
File size: 4.1 KB
RevLine 
[12468]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[12468]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
[12691]23using System.Collections.Generic;
[12468]24using System.Data.Linq;
[12691]25using System.Linq;
[12468]26
27namespace HeuristicLab.Services.Hive.DataAccess.Daos {
[15379]28  public class ProjectPermissionDao : GenericDao<Guid, ProjectPermission> {
29    public ProjectPermissionDao(DataContext dataContext) : base(dataContext) { }
[12468]30
[15379]31    public override ProjectPermission GetById(Guid id) {
[12468]32      throw new NotImplementedException();
33    }
[12691]34
[15379]35    public IEnumerable<ProjectPermission> GetByProjectId(Guid id) {
36      return GetByProjectIdGetByIdQuery(DataContext, id);
[12691]37    }
38
[15530]39    public bool CheckUserGrantedForProject(Guid projectId, IEnumerable<Guid> userAndGroupIds) {
[15577]40      string paramUserAndGroupIds = string.Join(",", userAndGroupIds.ToList().Select(x => string.Format("'{0}'", x)));
[15530]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) {
[15577]49      string paramIds = string.Join(",", grantedUserIds.ToList().Select(x => string.Format("'{0}'", x)));
[12691]50      if (!string.IsNullOrWhiteSpace(paramIds)) {
[15530]51        string query = string.Format(DeleteByProjectIdAndGrantedUserIdsQueryString, projectId, paramIds);
[12691]52        DataContext.ExecuteCommand(query);
53      }
54    }
55
[15530]56    public void DeleteByProjectIdsAndGrantedUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> grantedUserIds) {
[15577]57      string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x)));
58      string paramUserIds = string.Join(",", grantedUserIds.ToList().Select(x => string.Format("'{0}'", x)));
[15530]59      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) {
60        string query = string.Format(DeleteByProjectIdsAndGrantedUserIdsQueryString, paramProjectIds, paramUserIds);
61        DataContext.ExecuteCommand(query);
62      }
63    }
64
[12691]65    #region Compiled queries
[15379]66    private static readonly Func<DataContext, Guid, IEnumerable<ProjectPermission>> GetByProjectIdGetByIdQuery =
67      CompiledQuery.Compile((DataContext db, Guid projectId) =>
68        from projectPermission in db.GetTable<ProjectPermission>()
69        where projectPermission.ProjectId == projectId
70        select projectPermission);
[12691]71    #endregion
72
73    #region String queries
[15530]74    private const string DeleteByProjectIdAndGrantedUserIdsQueryString = @"
75      DELETE FROM [ProjectPermission]
[15628]76      WHERE ProjectId = {0}
[15530]77      AND GrantedUserId IN ({1});
78    ";
79    private const string DeleteByProjectIdsAndGrantedUserIdsQueryString = @"
80      DELETE FROM [ProjectPermission]
[15577]81      WHERE ProjectId IN ({0})
[15530]82      AND GrantedUserId IN ({1});
83    ";
84    private const string CheckUserGrantedForProjectQueryString = @"
85      SELECT COUNT(pp.ProjectId)
86      FROM [ProjectPermission] pp
[15628]87      WHERE pp.ProjectId = '{0}'
[15530]88      AND pp.GrantedUserId IN ({1})
89    ";
[15552]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    ";
[12691]96    #endregion
[12468]97  }
98}
Note: See TracBrowser for help on using the repository browser.