Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs @ 17928

Last change on this file since 17928 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 4.1 KB
RevLine 
[12468]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) 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 {
[16117]28  public class ProjectPermissionDao : GenericDao<Guid, ProjectPermission> {
29    public ProjectPermissionDao(DataContext dataContext) : base(dataContext) { }
[12468]30
[16117]31    public override ProjectPermission GetById(Guid id) {
[12468]32      throw new NotImplementedException();
33    }
[12691]34
[16117]35    public IEnumerable<ProjectPermission> GetByProjectId(Guid id) {
36      return GetByProjectIdGetByIdQuery(DataContext, id);
[12691]37    }
38
[16117]39    public bool CheckUserGrantedForProject(Guid projectId, IEnumerable<Guid> userAndGroupIds) {
40      string paramUserAndGroupIds = string.Join(",", userAndGroupIds.ToList().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.ToList().Select(x => string.Format("'{0}'", x)));
[12691]50      if (!string.IsNullOrWhiteSpace(paramIds)) {
[16117]51        string query = string.Format(DeleteByProjectIdAndGrantedUserIdsQueryString, projectId, paramIds);
[12691]52        DataContext.ExecuteCommand(query);
53      }
54    }
55
[16117]56    public void DeleteByProjectIdsAndGrantedUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> grantedUserIds) {
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)));
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
[16117]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
[16117]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    ";
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.