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.Hive.Contracts.Interfaces;
|
---|
10 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
11 | using HeuristicLab.Hive.Contracts;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Hive.Server.Console {
|
---|
14 | public partial class AddUserForm : Form {
|
---|
15 |
|
---|
16 | ResponseList<UserGroup> userGroups = null;
|
---|
17 | IUserRoleManager userRoleManager;
|
---|
18 | bool group;
|
---|
19 |
|
---|
20 | public AddUserForm(string addForm, bool group) {
|
---|
21 | this.group = group;
|
---|
22 | InitializeComponent();
|
---|
23 | this.Name = "Add " + addForm;
|
---|
24 |
|
---|
25 | lblOne.Text = addForm;
|
---|
26 | if (group) {
|
---|
27 | lblOne.Text += " Group";
|
---|
28 | }
|
---|
29 |
|
---|
30 | lblGroup.Text = addForm + " Groups";
|
---|
31 |
|
---|
32 | if (addForm == "User") {
|
---|
33 | addUser();
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void addUser() {
|
---|
38 | userRoleManager = ServiceLocator.GetUserRoleManager();
|
---|
39 | userGroups = userRoleManager.GetAllUserGroups();
|
---|
40 | cbGroups.Items.Add("none");
|
---|
41 | cbGroups.SelectedIndex = 0;
|
---|
42 | foreach (UserGroup ug in userGroups.List) {
|
---|
43 | cbGroups.Items.Add(ug.Name);
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | private void btnAdd_Click(object sender, EventArgs e) {
|
---|
48 | if (!group) {
|
---|
49 | if (tbOne.Text != "") {
|
---|
50 | User u = new User() { Name = tbOne.Text, Password = tbPwd.Text };
|
---|
51 | ResponseObject<User> respUser = userRoleManager.AddNewUser(u);
|
---|
52 | if (respUser.Success == true) {
|
---|
53 | if (cbGroups.SelectedIndex != 0) {
|
---|
54 | u = respUser.Obj;
|
---|
55 | foreach (UserGroup ug in userGroups.List) {
|
---|
56 | if (cbGroups.SelectedItem.ToString().Equals(ug.Name)) {
|
---|
57 | Response resp = userRoleManager.AddUserToGroup
|
---|
58 | (ug.Id, u.Id);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | } else {
|
---|
65 | UserGroup ug = new UserGroup { Name = tbOne.Text };
|
---|
66 | ResponseObject<UserGroup> respug = userRoleManager.AddNewUserGroup(ug);
|
---|
67 | if (respug.Success == true) {
|
---|
68 | if (!cbGroups.SelectedText.Equals("none")) {
|
---|
69 | ug = respug.Obj;
|
---|
70 | foreach (UserGroup ugs in userGroups.List) {
|
---|
71 | if (cbGroups.SelectedText.Equals(ugs.Name)) {
|
---|
72 | Response resp = userRoleManager.AddUserGroupToGroup
|
---|
73 | (ug.Id, ugs.Id);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | private void btnClose_Click(object sender, EventArgs e) {
|
---|
82 | this.Close();
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|