1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Data;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Services.Authentication.TestClient2
|
---|
11 | {
|
---|
12 | public partial class UserManagement : Form
|
---|
13 | {
|
---|
14 |
|
---|
15 | private AuthenticationService auth;
|
---|
16 | private DataTransfer.Application currentApplication;
|
---|
17 |
|
---|
18 | private DataTransfer.Application selectedApplication;
|
---|
19 | private DataTransfer.User selectedUser;
|
---|
20 | private DataTransfer.Role selectedRole;
|
---|
21 |
|
---|
22 | public UserManagement()
|
---|
23 | {
|
---|
24 | InitializeComponent();
|
---|
25 | Initialize();
|
---|
26 | }
|
---|
27 |
|
---|
28 | private void Initialize()
|
---|
29 | {
|
---|
30 | auth = new AuthenticationService();
|
---|
31 | bsApplications.DataSource = auth.GetApplications();
|
---|
32 | bsApplicationsCombo.DataSource = auth.GetApplications();
|
---|
33 | RefreshLists();
|
---|
34 | }
|
---|
35 |
|
---|
36 | private void RefreshLists()
|
---|
37 | {
|
---|
38 | if (currentApplication != null)
|
---|
39 | {
|
---|
40 | bsRoles.DataSource = auth.GetRoles(currentApplication.Id);
|
---|
41 | bsUsers.DataSource = auth.GetUsers(currentApplication.Id);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void cbxApplications_SelectedIndexChanged(object sender, EventArgs e)
|
---|
46 | {
|
---|
47 | this.currentApplication = (HeuristicLab.Services.Authentication.DataTransfer.Application)cbxApplications.SelectedItem;
|
---|
48 | RefreshLists();
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void btnNewApplication_Click(object sender, EventArgs e)
|
---|
52 | {
|
---|
53 | // new
|
---|
54 | //DataTransfer.Application = new DataTransfer.Application();
|
---|
55 | selectedApplication = (DataTransfer.Application)this.bsApplications.AddNew();
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void btnDeleteApplication_Click(object sender, EventArgs e)
|
---|
60 | {
|
---|
61 | if (this.dgvApplications.SelectedRows.Count > 0)
|
---|
62 | {
|
---|
63 | selectedApplication= ( DataTransfer.Application)this.dgvApplications.SelectedRows[0].DataBoundItem;
|
---|
64 | if (selectedApplication != null)
|
---|
65 | {
|
---|
66 | auth.DeleteApplication(selectedApplication.Id);
|
---|
67 | RefreshLists();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void btnUpdateApplication_Click(object sender, EventArgs e)
|
---|
73 | {
|
---|
74 |
|
---|
75 | if (selectedApplication != null)
|
---|
76 | {
|
---|
77 | if (selectedApplication.Id.Equals(Guid.Empty))
|
---|
78 | {
|
---|
79 | // insert
|
---|
80 | selectedApplication.Id = Guid.NewGuid();
|
---|
81 | auth.AddApplication(selectedApplication);
|
---|
82 | }
|
---|
83 | else
|
---|
84 | {
|
---|
85 | // update
|
---|
86 | auth.UpdateApplication(selectedApplication);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | private void dgvApplications_SelectionChanged(object sender, EventArgs e)
|
---|
94 | {
|
---|
95 | if (dgvApplications.SelectedRows.Count > 0)
|
---|
96 | {
|
---|
97 | selectedApplication = (DataTransfer.Application)dgvApplications.SelectedRows[0].DataBoundItem;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | private void dgvUsers_SelectionChanged(object sender, EventArgs e)
|
---|
102 | {
|
---|
103 | if (dgvUsers.SelectedRows.Count > 0)
|
---|
104 | {
|
---|
105 | selectedUser = (DataTransfer.User)dgvUsers.SelectedRows[0].DataBoundItem;
|
---|
106 | RefreshUserRolesList();
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | private void dgvRoles_SelectionChanged(object sender, EventArgs e)
|
---|
111 | {
|
---|
112 | if (dgvRoles.SelectedRows.Count > 0)
|
---|
113 | {
|
---|
114 | selectedRole = (DataTransfer.Role)dgvRoles.SelectedRows[0].DataBoundItem;
|
---|
115 | RefreshRoleUsersList();
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | private void btnUpdateRole_Click(object sender, EventArgs e)
|
---|
120 | {
|
---|
121 | if (selectedRole != null)
|
---|
122 | {
|
---|
123 | if (selectedRole.Id.Equals(Guid.Empty))
|
---|
124 | {
|
---|
125 | // insert
|
---|
126 | selectedRole.Id = Guid.NewGuid();
|
---|
127 | selectedRole.ApplicationId = currentApplication.Id;
|
---|
128 |
|
---|
129 | auth.AddRole(selectedRole);
|
---|
130 | }
|
---|
131 | else
|
---|
132 | {
|
---|
133 | // update
|
---|
134 | auth.UpdateRole(selectedRole);
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | private void btnNewRole_Click(object sender, EventArgs e)
|
---|
140 | {
|
---|
141 | selectedRole = (DataTransfer.Role)this.bsRoles.AddNew();
|
---|
142 | }
|
---|
143 |
|
---|
144 | private void btnDeleteRole_Click(object sender, EventArgs e)
|
---|
145 | {
|
---|
146 | if (this.dgvRoles.SelectedRows.Count > 0)
|
---|
147 | {
|
---|
148 | selectedRole = (DataTransfer.Role)this.dgvRoles.SelectedRows[0].DataBoundItem;
|
---|
149 | if (selectedRole != null)
|
---|
150 | {
|
---|
151 | auth.DeleteRole(selectedRole.Id);
|
---|
152 | RefreshLists();
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | private void btnNewUser_Click(object sender, EventArgs e)
|
---|
158 | {
|
---|
159 | selectedUser = (DataTransfer.User)this.bsUsers.AddNew();
|
---|
160 | }
|
---|
161 |
|
---|
162 | private void btnDeleteUser_Click(object sender, EventArgs e)
|
---|
163 | {
|
---|
164 | if (this.dgvUsers.SelectedRows.Count > 0)
|
---|
165 | {
|
---|
166 | selectedUser = (DataTransfer.User)this.dgvUsers.SelectedRows[0].DataBoundItem;
|
---|
167 | if (selectedUser != null)
|
---|
168 | {
|
---|
169 | auth.DeleteUser(selectedUser.Id);
|
---|
170 | RefreshLists();
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | private void btnUpdateUser_Click(object sender, EventArgs e)
|
---|
176 | {
|
---|
177 | if (selectedUser != null)
|
---|
178 | {
|
---|
179 | if (selectedUser.Id.Equals(Guid.Empty))
|
---|
180 | {
|
---|
181 | // insert
|
---|
182 | selectedUser.Id = Guid.NewGuid();
|
---|
183 | selectedUser.ApplicationId = currentApplication.Id;
|
---|
184 |
|
---|
185 | auth.AddUser(selectedUser);
|
---|
186 | }
|
---|
187 | else
|
---|
188 | {
|
---|
189 | // update
|
---|
190 | auth.UpdateUser(selectedUser);
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | private void btnRemoveRoleFromUser_Click(object sender, EventArgs e)
|
---|
196 | {
|
---|
197 | if (this.dgvUserRoles.SelectedRows.Count > 0)
|
---|
198 | {
|
---|
199 |
|
---|
200 | DataTransfer.Role role = (DataTransfer.Role)this.dgvUserRoles.SelectedRows[0].DataBoundItem;
|
---|
201 | if (role != null)
|
---|
202 | {
|
---|
203 | auth.RemoveUserFromRole(role.Id, selectedUser.Id);
|
---|
204 | RefreshUserRolesList();
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | private void btnAddRoleToUser_Click(object sender, EventArgs e)
|
---|
210 | {
|
---|
211 | if (this.dgvUserRolesAll.SelectedRows.Count > 0)
|
---|
212 | {
|
---|
213 | DataTransfer.Role role = (DataTransfer.Role)this.dgvUserRolesAll.SelectedRows[0].DataBoundItem;
|
---|
214 | if (role != null)
|
---|
215 | {
|
---|
216 | auth.AddUserToRole( role.Id,selectedUser.Id);
|
---|
217 | RefreshUserRolesList();
|
---|
218 | }
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | private void RefreshUserRolesList()
|
---|
223 | {
|
---|
224 | bsUserRoles.DataSource = auth.GetRolesForUser(selectedUser.Id);
|
---|
225 | }
|
---|
226 |
|
---|
227 | private void RefreshRoleUsersList()
|
---|
228 | {
|
---|
229 | bsRoleUsers.DataSource = auth.GetUsersInRole(selectedRole.Id);
|
---|
230 | }
|
---|
231 |
|
---|
232 | private void btnRemoveUserFromRole_Click(object sender, EventArgs e)
|
---|
233 | {
|
---|
234 | if (this.dgvRoleUsers.SelectedRows.Count > 0)
|
---|
235 | {
|
---|
236 |
|
---|
237 | DataTransfer.User user = (DataTransfer.User)this.dgvRoleUsers.SelectedRows[0].DataBoundItem;
|
---|
238 | if (user != null)
|
---|
239 | {
|
---|
240 | auth.RemoveUserFromRole(selectedRole.Id, user.Id);
|
---|
241 | RefreshRoleUsersList();
|
---|
242 | }
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | private void btnAddUserToRole_Click(object sender, EventArgs e)
|
---|
247 | {
|
---|
248 | if (this.dgvRoleUsersAll.SelectedRows.Count > 0)
|
---|
249 | {
|
---|
250 | DataTransfer.User user = (DataTransfer.User)this.dgvRoleUsersAll.SelectedRows[0].DataBoundItem;
|
---|
251 | if (user != null)
|
---|
252 | {
|
---|
253 | auth.AddUserToRole(selectedRole.Id, user.Id);
|
---|
254 | RefreshRoleUsersList();
|
---|
255 | }
|
---|
256 | }
|
---|
257 | }
|
---|
258 |
|
---|
259 |
|
---|
260 | }
|
---|
261 | }
|
---|