1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
6 | using HeuristicLab.Security.Contracts.BusinessObjects;
|
---|
7 | using HeuristicLab.Security.DataAccess;
|
---|
8 | using HeuristicLab.Security.ADODataAccess.TableAdapterWrapper;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Security.ADODataAccess {
|
---|
11 | class UserGroupAdapter: DataAdapterBase<
|
---|
12 | dsSecurityTableAdapters.UserGroupTableAdapter,
|
---|
13 | UserGroup,
|
---|
14 | dsSecurity.UserGroupRow>,
|
---|
15 | IUserGroupAdapter {
|
---|
16 | public UserGroupAdapter() :
|
---|
17 | base(new UserGroupAdapterWrapper()) {
|
---|
18 | }
|
---|
19 |
|
---|
20 | private ManyToManyRelationHelper<
|
---|
21 | dsSecurityTableAdapters.PermissionOwner_UserGroupTableAdapter,
|
---|
22 | dsSecurity.PermissionOwner_UserGroupRow> manyToManyRelationHelper = null;
|
---|
23 |
|
---|
24 | private ManyToManyRelationHelper<dsSecurityTableAdapters.PermissionOwner_UserGroupTableAdapter,
|
---|
25 | dsSecurity.PermissionOwner_UserGroupRow> ManyToManyRelationHelper {
|
---|
26 | get {
|
---|
27 | if (manyToManyRelationHelper == null) {
|
---|
28 | manyToManyRelationHelper =
|
---|
29 | new ManyToManyRelationHelper<dsSecurityTableAdapters.PermissionOwner_UserGroupTableAdapter,
|
---|
30 | dsSecurity.PermissionOwner_UserGroupRow>(new PermissionOwner_UserGroupAdapterWrapper(), 0);
|
---|
31 | }
|
---|
32 |
|
---|
33 | manyToManyRelationHelper.Session = Session as Session;
|
---|
34 |
|
---|
35 | return manyToManyRelationHelper;
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | private IPermissionOwnerAdapter permOwnerAdapter = null;
|
---|
40 |
|
---|
41 | private IPermissionOwnerAdapter PermOwnerAdapter {
|
---|
42 | get {
|
---|
43 | if (permOwnerAdapter == null)
|
---|
44 | permOwnerAdapter =
|
---|
45 | this.Session.GetDataAdapter<PermissionOwner, IPermissionOwnerAdapter>();
|
---|
46 |
|
---|
47 | return permOwnerAdapter;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override dsSecurity.UserGroupRow ConvertObj(UserGroup group,
|
---|
52 | dsSecurity.UserGroupRow row) {
|
---|
53 | if (group != null && row != null) {
|
---|
54 | row.PermissionOwnerId = group.Id;
|
---|
55 |
|
---|
56 | return row;
|
---|
57 | } else {
|
---|
58 | return null;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override UserGroup ConvertRow(dsSecurity.UserGroupRow row,
|
---|
63 | UserGroup group) {
|
---|
64 | if (group != null && row != null) {
|
---|
65 | group.Id = row.PermissionOwnerId;
|
---|
66 | PermOwnerAdapter.GetById(group);
|
---|
67 |
|
---|
68 | ICollection<Guid> permissionOwners =
|
---|
69 | ManyToManyRelationHelper.GetRelationships(group.Id);
|
---|
70 |
|
---|
71 | group.Members.Clear();
|
---|
72 | foreach (Guid permissionOwner in permissionOwners) {
|
---|
73 | PermissionOwner permOwner =
|
---|
74 | PermOwnerAdapter.GetByIdPolymorphic(permissionOwner);
|
---|
75 |
|
---|
76 | group.Members.Add(permOwner);
|
---|
77 | }
|
---|
78 |
|
---|
79 | return group;
|
---|
80 | } else {
|
---|
81 | return null;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | #region IUserGroupAdapter Members
|
---|
86 |
|
---|
87 | protected override void doUpdate(UserGroup group) {
|
---|
88 | if (group != null) {
|
---|
89 | PermOwnerAdapter.Update(group);
|
---|
90 |
|
---|
91 | base.doUpdate(group);
|
---|
92 |
|
---|
93 | List<Guid> relationships =
|
---|
94 | new List<Guid>();
|
---|
95 | foreach (PermissionOwner permOwner in group.Members) {
|
---|
96 | PermOwnerAdapter.UpdatePolymorphic(permOwner);
|
---|
97 |
|
---|
98 | relationships.Add(permOwner.Id);
|
---|
99 | }
|
---|
100 |
|
---|
101 | ManyToManyRelationHelper.UpdateRelationships(group.Id,
|
---|
102 | relationships);
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | protected override bool doDelete(UserGroup group) {
|
---|
107 | if (group != null) {
|
---|
108 | //delete all relationships
|
---|
109 | ManyToManyRelationHelper.UpdateRelationships(group.Id,
|
---|
110 | new List<Guid>());
|
---|
111 |
|
---|
112 | return base.doDelete(group) &&
|
---|
113 | PermOwnerAdapter.Delete(group);
|
---|
114 | }
|
---|
115 |
|
---|
116 | return false;
|
---|
117 | }
|
---|
118 |
|
---|
119 | public UserGroup GetByName(string name) {
|
---|
120 | UserGroup group = new UserGroup();
|
---|
121 | PermissionOwner permOwner =
|
---|
122 | PermOwnerAdapter.GetByName(name);
|
---|
123 |
|
---|
124 | if (permOwner != null)
|
---|
125 | return GetById(permOwner.Id);
|
---|
126 | else
|
---|
127 | return null;
|
---|
128 | }
|
---|
129 |
|
---|
130 | public ICollection<UserGroup> MemberOf(Guid permissionOwnerId) {
|
---|
131 | return base.FindMultiple(
|
---|
132 | delegate() {
|
---|
133 | return Adapter.GetDataByMemberOf(permissionOwnerId);
|
---|
134 | }
|
---|
135 | );
|
---|
136 | }
|
---|
137 |
|
---|
138 | #endregion
|
---|
139 | }
|
---|
140 | }
|
---|