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 | using HeuristicLab.Services.Authentication.DataTransfer;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Services.Authentication.TestClient
|
---|
12 | {
|
---|
13 | public partial class UserManagement : Form
|
---|
14 | {
|
---|
15 |
|
---|
16 | AuthenticationService service;
|
---|
17 | Guid applicationId = new Guid("04371D20-8FD4-4607-A632-42C8D186786B");
|
---|
18 |
|
---|
19 |
|
---|
20 | public UserManagement()
|
---|
21 | {
|
---|
22 | InitializeComponent();
|
---|
23 | Initialize();
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | private void Initialize()
|
---|
28 | {
|
---|
29 | service = new AuthenticationService();
|
---|
30 | if (service != null)
|
---|
31 | {
|
---|
32 |
|
---|
33 |
|
---|
34 | RefreshApplicationlist();
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | private void RefreshApplicationlist()
|
---|
39 | {
|
---|
40 | this.bsApplications.DataSource = service.GetApplications();
|
---|
41 | RefreshRolelist();
|
---|
42 | RefreshUserlist();
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void RefreshRolelist()
|
---|
46 | {
|
---|
47 | this.bsRoles.DataSource = service.GetRoles(applicationId);
|
---|
48 | }
|
---|
49 |
|
---|
50 | private void RefreshUserlist()
|
---|
51 | {
|
---|
52 | this.bsUsers.DataSource = service.GetUsers(applicationId);
|
---|
53 | }
|
---|
54 |
|
---|
55 | private void RefreshRoleUserlist(Guid roleId)
|
---|
56 | {
|
---|
57 | this.bsRoleUsers.DataSource = service.GetUsersInRole(roleId);
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void dgvUsers_SelectionChanged(object sender, EventArgs e)
|
---|
61 | {
|
---|
62 | // show detail
|
---|
63 | if (dgvUsers.SelectedRows.Count == 1)
|
---|
64 | {
|
---|
65 | User user = (User)dgvUsers.SelectedRows[0].DataBoundItem;
|
---|
66 | bsUser.DataSource = user;
|
---|
67 | bsUserRoles.DataSource = service.GetRolesForUser(user.Id);
|
---|
68 | tcUser.Enabled = false;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void dgvRoles_SelectionChanged(object sender, EventArgs e)
|
---|
73 | {
|
---|
74 | if (dgvRoles.SelectedRows.Count == 1)
|
---|
75 | {
|
---|
76 | Role role = (Role)dgvRoles.SelectedRows[0].DataBoundItem;
|
---|
77 | bsRole.DataSource = role;
|
---|
78 | IEnumerable<User> _l = service.GetUsersInRole(role.Id);
|
---|
79 | bsRoleUsers.DataSource = service.GetUsersInRole(role.Id);
|
---|
80 | btnDeleteRole.Enabled = true;
|
---|
81 | tcRole.Enabled = true;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | private void btnNewRole_Click(object sender, EventArgs e)
|
---|
86 | {
|
---|
87 | // new Role
|
---|
88 | Role role = new Role();
|
---|
89 | role.ApplicationId = applicationId;
|
---|
90 | bsRole.DataSource = role;
|
---|
91 | tcRole.Enabled = true;
|
---|
92 | }
|
---|
93 |
|
---|
94 | private void btnNewUser_Click(object sender, EventArgs e)
|
---|
95 | {
|
---|
96 | User user = new User();
|
---|
97 | user.ApplicationId = applicationId;
|
---|
98 | bsUser.DataSource = user;
|
---|
99 | tcUser.Enabled = true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | private void btnSaveUser_Click(object sender, EventArgs e)
|
---|
103 | {
|
---|
104 | User user = (User)bsUser.DataSource;
|
---|
105 | tcUser.Enabled = false;
|
---|
106 | service.InsertUser(user);
|
---|
107 | RefreshUserlist();
|
---|
108 |
|
---|
109 | }
|
---|
110 |
|
---|
111 | private void btnSaveRole_Click(object sender, EventArgs e)
|
---|
112 | {
|
---|
113 | Role role = (Role)bsRole.DataSource;
|
---|
114 | role.ApplicationId = applicationId;
|
---|
115 | service.InsertRole(role);
|
---|
116 | tcRole.Enabled = false;
|
---|
117 | RefreshRolelist();
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | private void btnAddUserToRole_Click(object sender, EventArgs e)
|
---|
123 | {
|
---|
124 | if (dgvRoleAvailableUsers.SelectedRows.Count == 1)
|
---|
125 | {
|
---|
126 | User user = (User)dgvRoleAvailableUsers.SelectedRows[0].DataBoundItem;
|
---|
127 | Role role = (Role)bsRole.DataSource;
|
---|
128 | role.ApplicationId = applicationId;
|
---|
129 | user.ApplicationId = applicationId;
|
---|
130 | service.AddUserToRole(role.Id, user.Id);
|
---|
131 | RefreshRoleUserlist(role.Id);
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | private void btnDeleteRole_Click(object sender, EventArgs e)
|
---|
136 | {
|
---|
137 | if (dgvRoles.SelectedRows.Count == 1)
|
---|
138 | {
|
---|
139 | Role role = (Role)dgvRoles.SelectedRows[0].DataBoundItem;
|
---|
140 | service.DeleteRole(role.Id);
|
---|
141 | RefreshRolelist();
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | private void btnRemoveUserFromRole_Click(object sender, EventArgs e)
|
---|
146 | {
|
---|
147 | // remove from role ..
|
---|
148 | if (dgvRoleAssignedUsers.SelectedRows.Count == 1)
|
---|
149 | {
|
---|
150 | User user = (User)dgvRoleAssignedUsers.SelectedRows[0].DataBoundItem;
|
---|
151 | Role role = (Role)bsRole.DataSource;
|
---|
152 |
|
---|
153 | service.RemoveUserFromRole(role.Id, user.Id);
|
---|
154 | RefreshRoleUserlist(role.Id);
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | private void cbxApplication_SelectedIndexChanged(object sender, EventArgs e)
|
---|
159 | {
|
---|
160 | HeuristicLab.Services.Authentication.DataTransfer.Application application = (HeuristicLab.Services.Authentication.DataTransfer.Application)cbxApplication.SelectedItem;
|
---|
161 | if (application != null)
|
---|
162 | {
|
---|
163 | applicationId = application.Id;
|
---|
164 | RefreshApplicationlist();
|
---|
165 | }
|
---|
166 |
|
---|
167 | }
|
---|
168 |
|
---|
169 | private void btnDeleteUser_Click(object sender, EventArgs e)
|
---|
170 | {
|
---|
171 | if (dgvUsers.SelectedRows.Count == 1)
|
---|
172 | {
|
---|
173 | User user = (User)dgvUsers.SelectedRows[0].DataBoundItem;
|
---|
174 | if (user != null)
|
---|
175 | {
|
---|
176 | service.DeleteUser(user.Id);
|
---|
177 | RefreshUserlist();
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | private void bsApplications_CurrentChanged(object sender, EventArgs e)
|
---|
183 | {
|
---|
184 |
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 | }
|
---|
192 | }
|
---|