Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Security.ADODataAccess/3.2/PermissionOwnerAdapter.cs @ 2211

Last change on this file since 2211 was 1656, checked in by svonolfe, 16 years ago

Implemented large parts of the security DAL (#597)

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.DataAccess.ADOHelper;
6using HeuristicLab.Security.Contracts.BusinessObjects;
7using HeuristicLab.Security.DataAccess;
8using HeuristicLab.Security.ADODataAccess.TableAdapterWrapper;
9
10namespace HeuristicLab.Security.ADODataAccess {
11  class PermissionOwnerAdapter: DataAdapterBase<
12      dsSecurityTableAdapters.PermissionOwnerTableAdapter,
13      PermissionOwner,
14      dsSecurity.PermissionOwnerRow>,
15      IPermissionOwnerAdapter {
16    public PermissionOwnerAdapter() :
17      base(new PermissionOwnerAdapterWrapper()) {
18    }
19
20    private IUserAdapter userAdapter = null;
21
22    private IUserAdapter UserAdapter {
23      get {
24        if (userAdapter == null)
25          userAdapter =
26            this.Session.GetDataAdapter<User, IUserAdapter>();
27
28        return userAdapter;
29      }
30    }
31
32    private IUserGroupAdapter userGroupAdapter = null;
33
34    private IUserGroupAdapter UserGroupAdapter {
35      get {
36        if (userGroupAdapter == null)
37          userGroupAdapter =
38            this.Session.GetDataAdapter<UserGroup, IUserGroupAdapter>();
39
40        return userGroupAdapter;
41      }
42    }
43
44    protected override dsSecurity.PermissionOwnerRow ConvertObj(PermissionOwner permOwner,
45      dsSecurity.PermissionOwnerRow row) {
46      if (row != null && permOwner != null) {
47        row.PermissionOwnerId = permOwner.Id;
48        row.Name = permOwner.Name;
49
50        return row;
51      } else {
52        return null;
53      }
54    }
55
56    protected override PermissionOwner ConvertRow(dsSecurity.PermissionOwnerRow row,
57      PermissionOwner permOwner) {
58      if (row != null && permOwner != null) {
59        permOwner.Id = row.PermissionOwnerId;
60
61        if (!row.IsNameNull())
62          permOwner.Name = row.Name;
63        else
64          permOwner.Name = String.Empty;
65
66        return permOwner;
67      } else {
68        return null;
69      }
70    }
71
72    #region IPermissionOwnerAdapter Members
73
74    public PermissionOwner GetByName(string name) {
75      return base.FindSingle(
76        delegate() {
77          return Adapter.GetDataByName(name);
78        });
79    }
80
81    public bool GetById(PermissionOwner permOwner) {
82      if (permOwner != null) {
83        dsSecurity.PermissionOwnerRow row =
84          GetRowById(permOwner.Id);
85
86        if (row != null) {
87          Convert(row, permOwner);
88
89          return true;
90        }
91      }
92
93      return false;
94    }
95
96    #endregion
97
98    #region IPolymorphicDataAdapter<PermissionOwner> Members
99
100    public void UpdatePolymorphic(PermissionOwner obj) {
101      if (obj is User) {
102        UserAdapter.Update(obj as User);
103      } else if (obj is UserGroup) {
104        UserGroupAdapter.Update(obj as UserGroup);
105      } else {
106        this.Update(obj);
107      }
108    }
109
110    public PermissionOwner GetByIdPolymorphic(Guid id) {
111      UserGroup group =
112        UserGroupAdapter.GetById(id);
113
114      if (group != null)
115        return group;
116      else {
117        User user =
118          UserAdapter.GetById(id);
119
120        if (user != null)
121          return user;
122        else {
123          return this.GetById(id);
124        }
125      }
126    }
127
128    public bool DeletePolymorphic(PermissionOwner obj) {
129      if (obj is User) {
130        return UserAdapter.Delete(obj as User);
131      } else if (obj is UserGroup) {
132        return UserGroupAdapter.Delete(obj as UserGroup);
133      } else {
134        return this.Delete(obj);
135      }
136    }
137
138    #endregion
139  }
140}
Note: See TracBrowser for help on using the repository browser.